发布网友
共2个回答
热心网友
let ages= [{'id':'10','age':18},{'id':'11','age':20},{'id':'11','age':20}]
let arrNew=[]
arrNew = ages.filter((num, i, arr) => {
let arrId = [] // 用于存所有的id
ages.forEach(element => arrId.push(element.id));
//在原始数组中该id的第一个索引等于当前索引就留下
return arrId.indexOf(num.id,0)===i
});
console.log(arrNew)
热心网友
Lambda 表达式var hash = {};<br>//arr是要去重的对象数组arr = arr.rece(function(item, next) { hash[next.name] ? '' : hash[next.name] = true && item.push(next); return item}, [])