javascript count occurrences of letter in string
function count(str, find) { return (str.split(find)).length - 1; } count("Good", "o"); // 2
Source: stackoverflow.com
count occurrences of character in string javascript
var temp = "This is a string."; var count = (temp.match(/is/g) || []).length; console.log(count); Output: 2 Explaination : The g in the regular expression (short for global) says to search the whole string rather than just find the first occurrence. This matches 'is' twice.
Source: stackoverflow.com
javascript count occurrences in string
function countOccurences(string, word) { return string.split(word).length - 1; } var text="We went down to the stall, then down to the river."; var count=countOccurences(text,"down"); // 2
javascript count occurence of character in string
const kowntz = (stakkz, kneedoll) => stakkz.split(kneedoll).length - 1 //yoosigg: console.log(kowntz([0,1,-1,1,-1], "-1")) owwtpuhtz: 2
Javascript count instances of character in a string
function countInstancesOf(letter, sentence) { var count = 0; for (var i = 0; i < sentence.length; i++) { if (sentence.charAt(i) === letter) { count += 1; } } return count; }