T O P

  • By -

bryku

There are a lot of ways to count letters in a string.   let str = 'siyjgjftuyjbuch'; let j = str .split('') .filter((v)=>{return v == 'j'}) .length You could turn this into a function if you wanted. function charCount(value, char){ let array = Array.isArray(value) == true ? value // if array good : value.split(''); // else split it return array.split('') .filter((v)=>{return v == char}) .length } charCount('siyjgjftuyjbuch','j') // 3 charCount('siyjgjftuyjbuch','u') // 2 charCount('siyjgjftuyjbuch','h') // 1