<script type="text/javascript">
var str="hellomainlanguageoo";
var obj={};
for(var i=0;i<str.length;i++){
var chars=str.charAt(i);
if(obj[chars]){
obj[chars]++;
}else{
obj[chars]=1;
}
}
console.log(obj);
var max=0;
var maxChar=null;
for(var chars in obj){
if(max<obj[chars]){
max=obj[chars];
maxChar=chars;
}
}
console.log("出现最多的是"+maxChar+"总共出现"+max+"次");
</script>
时间: 2024-10-12 00:25:10