Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #count #specific #letters #string #js
ADD COMMENT
Topic
Name
4+3 =