Answers for "count the amount of occurence js"

1

how to count specific letters in string js

console.log(("str1,str2,str3,str4".match(/,/g) || []).length); //logs 3

console.log(("str1,str2,str3,str4".match(new RegExp("str", "g")) || []).length); //logs 4
Posted by: Guest on September-08-2020
0

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"); // => { a: 2, b: 1, s: 3, d: 1 }
Posted by: Guest on June-20-2020

Code answers related to "count the amount of occurence js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language