The most frequent characters in a string count this number [Implementation code]_javascript skills
var str = 'asdfssaaasasasasaa'; var json = {}; for (var i = 0; i < str.length; i++) { if(!json[str.charAt(i)]){ json[str.charAt(i)] = 1; }else{ json[str.charAt(i)]++; } }; var iMax = 0; var iIndex = ''; for(var i in json){ if(json[i]>iMax){ iMax = json[i]; iIndex = i; } } alert('出现次数最多的是:'+iIndex+'出现'+iMax+'次');
The above statistics of the most frequent characters in a string [implementation code] are all the content shared by the editor. For more related content, please pay attention to PHP Chinese website (www.php.cn)!