var str = 'abcdacbabcbababcbabcabdefefefef'
var obj = {}
for(var i in str){
if(obj[str[i]]){
obj[str[i]]++
}else{
obj[str[i]] = 1
}
}
console.log(obj)
统计字符串中每个字符的个数?
最新推荐文章于 2021-10-27 21:17:52 发布
var str = 'abcdacbabcbababcbabcabdefefefef'
var obj = {}
for(var i in str){
if(obj[str[i]]){
obj[str[i]]++
}else{
obj[str[i]] = 1
}
}
console.log(obj)