function maxStr(str){ var obj = {} var max = { item:[],count:1 }; str.split('').forEach(item=>{ obj[item] == undefined ? obj[item] = 1 : obj[item]++; }) for(var item of Object.entries(obj)){ if(item[1]>max.count){ max.item = [] max.item.push(item[0]) max.count = item[1] }else if(item[1]==max.count && max.item.indexOf(item[0])==-1){ max.item.push(item[0]) max.count = item[1] } } return max.item + '出现了最多的次数,最多为' + max.count + '次.'; } console.log(maxStr('assdsdfsfsjiwaaasdmsdifjsfaaaaas')) //a,s出现了最多的次数,最多为9次.