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 counts = {}; yourstring.split('').map(function(ch) { counts[ch] = (counts[ch] || 0) + 1; });
Or be hip and use map/reduce:
var counts = yourstring.split('').reduce(function(dst, c) { dst[c] = (dst[c] || 0) + 1; return dst; }, {});