javascript count number of specific character in string code example
Example 1: how to count specific letters in string js
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
Example 2: javascript count character in string
var str = "Hello World!";
var n = str.length;