var arr = [1, 2, 4, 6, 6, 4, 4, 7, 1, 2, 2];
var obj = {};
for (var i = 0, len = arr.length; i <= len - 1; i++){
var item = arr[i];
obj[item] = (obj[item] + 1) || 1;
}
console.log(obj)
var arr = [1, 2, 4, 6, 6, 4, 4, 7, 1, 2, 2];
var obj = {};
for (var i = 0, len = arr.length; i <= len - 1; i++){
var item = arr[i];
obj[item] = (obj[item] + 1) || 1;
}
console.log(obj)
本文标题:统计数组中重复元素的个数
本文链接:https://www.haomeiwen.com/subject/dsbbuqtx.html
网友评论