利用reduce函数处理,直接上代码!
let data = [{'name':'晓明','id':1},{'name':'德华','id':2},{'name':'德华','id':2},{'name':'晓明','id':1},]
var obj = {};
let arr = data.reduce(function (item, next) {
obj[next.id] ? '' : obj[next.id] = true && item.push(next);
return item;
}, []);
console.log(arr)
结果如下: