I need to count the number of occurrences of a character in a string.
For example, suppose my string contains:
var mainStr = \"str1,str2,str3,str4\";
ok, an other one with regexp - probably not fast, but short and better readable then others, in my case just '_' to count
'_'
key.replace(/[^_]/g,'').length
just remove everything that does not look like your char but it does not look nice with a string as input