string letter count javascript code example
Example 1: js character certain count
var str = "Hello Lewes";
var ch = 'e';
var count = str.split("e").length - 1;
console.log(count);
/*
Output: 3
*/
Example 2: how get count of letters in javascript
//when use length for string this will be return the count of charactor
//in string
$("#about_me_textarea").val().length
Example 3: 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