var arr = [
{name: 'aa',age: 1},
{name: 'bb',age: 1},
{name: 'cc',age: 1},
{name: 'cc',age: 1},
{name: 'cc',age: 1},
{name: 'dd',age: 1},
{name: 'dd',age: 1},
{name: 'cc',age: 1},
{name: 'cc',age: 1},
{name: 'dd',age: 1},
{name: 'dd',age: 1},
{name: 'e',age: 1},
{name: 'e',age: 1},
{name: 'dd',age: 1},
];
//添加属性number:次数
arr.forEach(tem => {
tem.number = 1;
});
//去重,并添加次数
for (var i = 0;i < arr.length; i++){
for (var j = i+1;j < arr.length;j++){
if (arr[i].name == arr[j].name){
arr.splice(j,1);
j--;
arr[i].number++;
}
}
}