Javascript Count Ocorrências de carta em cordas
function count(str, find) {
return (str.split(find)).length - 1;
}
count("Good", "o"); // 2
DenverCoder1
function count(str, find) {
return (str.split(find)).length - 1;
}
count("Good", "o"); // 2
console.log(("str1,str2,str3,str4".match(/,/g) || []).length); //logs 3
console.log(("str1,str2,str3,str4".match(new RegExp("str", "g")) || []).length); //logs 4