How to write a javascript code that counts each character occurrence in a string ?
e.g String is : Hello World Output : count of H -> 1 count of e -&
var splitWord = "Hello World".split(''); var letters = {}; for(var i in splitWord) { var letter = splitWord[i]; if(letter == ' ') continue; if(typeof letters[letter] == 'undefined') { letters[letter] = 0; } letters[letter]++; } console.dir(letters);