Now this is a very old thread i've come across but as many have pushed their answer's, here is mine in a hope to help someone with this simple code.
var search_value = "This is a dummy sentence!";var letter = 'a'; /*Can take any letter, have put in a var if anyone wants to use this variable dynamically*/letter = letter && "string" === typeof letter ? letter : "";var count;for (var i = count = 0; i < search_value.length; count += (search_value[i++] == letter));console.log(count);
I'm not sure if it is the fastest solution but i preferred it for simplicity and for not using regex (i just don't like using them!)