本篇文章给大家分享的内容是s数组去重以及如何统计字符串出现最多的字符的代码分享,有着一定的参考价值,有需要的朋友可以参考一下
数组去重:
数组去重function test(str){
let len = str.length;
let strtmp = [];
for(let i = 0;i
if (strtmp.indexOf(str[i])< 1){
strtmp.push(str[i]);
}
}
console.log(strtmp);
}
let abc = [0,2,3,5,2,1,9,3,9,1];
test(abc);
查找字符串出现最多的:
1111$(function(){
$('.btn').click(function(){
let num = $('.num').val();
// console.log(num);
let len = num.length;
let json = {};
for (let i=0;i
if(!json[num.charAt(i)]){
json[num.charAt(i)]=1;
}else
{
json[num.charAt(i)]++;
}
}
let max = 0;
let word = '';
for(var i in json){
if (json[i]> max){
max = json [i];
word = i;
}
}
console.log('the word is'+word,'count is'+max);
})
})
awqewqewqewqe
22222
相关推荐: