count char in javascript code example
Example 1: count value a to b character javascript
const recorrences = ['a', 'b', 'c', 'a', 'b','a']
.map(i => !!~i.indexOf('a'))
.filter(i => i)
.length;
console.log(`recorrences ${recorrences}`)
Example 2: count value a to b character javascript
let counter = str => {
return str.split('').reduce((total, letter) => {
total[letter] ? total[letter]++ : total[letter] = 1;
return total;
}, {});
};
counter("aabsssd");
Example 3: javascript count character in string
var str = "Hello World!";
var n = str.length;