var str = "asdkfhsodjcpeksoxshieorjsa"; var obj = {}; for(var i=0;i<str.length;i++){ if(!obj[str.charAt(i)]){ obj[str.charAt(i)] = 1; }else{ obj[str.charAt(i)]++; } }; var maxNum = 0; var letter = ‘‘; for(var i in obj){ if(obj[i]>maxNum){ maxNum=obj[i]; letter = i } } console.log(‘出现次数最多的是:‘+letter+‘出现‘+maxNum+‘次‘)
原文地址:https://www.cnblogs.com/shy0113/p/11517326.html
时间: 2024-10-15 10:04:50