Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

count repeated characters in a string in react

var obj={}
var repeats=[];
str='banana'

for(x = 0, length = str.length; x < length; x++) {
    var l = str.charAt(x)
    obj[l] = (isNaN(obj[l]) ? 1 : obj[l] + 1);
}

console.log(obj)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #count #repeated #characters #string #react
ADD COMMENT
Topic
Name
7+8 =