var names = [‘suga‘, ‘bts‘, ‘suga‘, ‘v‘, ‘jimin‘];
var countedNames = names.reduce(function (allNames, name) {
if (name in allNames) {
allNames[name]++;
}
else {
allNames[name] = 1;
}
return allNames;
}, {});
console.log(countedNames);
原文地址:https://www.cnblogs.com/suga/p/8525342.html
时间: 2024-11-09 10:30:09