作者:H_debug | 来源:互联网 | 2023-01-28 18:16
统计字符串中出现的字母 letstraabbabbbcchhddfgh;letobj{};for(varvofstr){if(obj[v]&&obj[v].valuev){ob
统计字符串中出现的字母
let str = "aabbabbbcchhddfgh";
let obj = {};
for(var v of str){
if(obj[v]&&obj[v].value == v){
obj[v].count = ++obj[v].count;
}else{
obj[v] = {};
obj[v].count = 1;
obj[v].value = v;
}
}
for(key in obj){
console.log(obj[key].value + '=' + obj[key].count + '');