Count the number of occurrences of a character in a string in Javascript
I have updated this answer. I like the idea of using a match better, but it is slower: Expand snippet Use a regular expression literal if you know what you are searching for beforehand, if not you can use the RegExp constructor, and pass in the g flag as an argument. match returns null with … Read more