Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Javascript #count #instances #character #string
ADD COMMENT
Topic
Name
6+1 =