// 统计字符串每个字母出现的次数 let str = 'asdfssaaasasasasaa' let obj = str.split('').reduce(function (prev, item) { // prev的初始值是空对象 if (prev[item]) { prev[item]++ } else { prev[item] = 1 } return prev }, {}) console.log(obj)
标签:字母,reduce,item,let,字符串,prev From: https://www.cnblogs.com/zhulongxu/p/16616464.html