JavaScript program to check the number of occurrences of a character in a string:

python tutorials and learn python

Created with Sketch.

JavaScript program to check the number of occurrences of a character in a string:

function countChar(str, char) {
  let count = 0;
  for (let i = 0; i < str.length; i++) {
    if (str[i] == char) {
      count++;
    }
  }
  return count;
}

console.log(countChar("javascript", "a"));

Leave a Reply

Your email address will not be published. Required fields are marked *