var str = 'asdddasdfdseeeeeweeeeeeeeeeeee';
var json = {}; // 定义json一个对象
for(var i = 0; i < str.length; i++){ // 遍历字符串str
if(!json[str.charAt(i)]){ // 判断str字符串的第i位是否在json中存在
json[str.charAt(i)] = 1; // 如果不存在,则在json中以键值对的形式存储str的第i位,值为1
}else{
json[str.charAt(i)]++; // 如果存在累加json中对应键的值
}
}
var max = 0; // 定义字符串出现最多次数的数值
var maxStr = ''; // 定义出现最多次数的字符串
for(var i in json){ // 遍历json对象
if(json[i] > max){ // 循环判断max与json中每个键对应值的大小
max = json[i]; // 如果json中的值大于max,则把该值赋给max
maxStr = i;
}
}
console.log('出现最多次数字符串:' + maxStr + ',出现次数:' + max);