代码原文
console.log('计算数组中每个元素出现的次数');
let arr = ['b', 'c', 'b', 'c', 'a','b','c'];
let arrTool = arr.reduce((sum, item) => {
if (item in sum) {
sum[item]++;
} else {
sum[item] = 1
}
return sum;
}, {})
console.log('arrTool', arrTool); // arrTool {b: 3, c: 3, a: 1}
可以得出结果