programming-examples/js/Functions/Write a JavaScript function to get the number of occurrences of each letter in specified string..js
2019-11-15 12:59:38 +01:00

6 lines
239 B
JavaScript

function Char_Counts(str1) {
var uchars = {};
str1.replace(/\S/g, function(l){uchars[l] = (isNaN(uchars[l]) ? 1 : uchars[l] + 1);});
return uchars;
}
console.log(Char_Counts("The quick brown fox jumps over the lazy dog"));