Answers for "find count of character in string javascript"

2

js character certain count

var str = "Hello Lewes";
var ch = 'e';
 
var count = str.split("e").length - 1;
console.log(count);
 
/*
    Output: 3
*/
Posted by: Guest on October-09-2020
-1

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;
}
Posted by: Guest on June-20-2021

Code answers related to "find count of character in string javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language