判断数组每个值出现了几次
var arr = ["c", "a", "z", "a", "x", "a"];
var o = {};
for (var i = 0; i < arr.length; i++) {
var item = arr[i];
if (o[item]) {
o[item]++;
} else {
o[item] = 1;
}
}
console.log(o);
Sometimes you need to applaud yourself