function arrayObjectDeDuplication(data, field) {
let obj = {}
let newData = []
newData = data.reduce((cur, next) => {
obj[next[field]] ? "" : obj[next[field]] = true && cur.push(next);
return cur
}, [])
return newData
}
let data = [{id:1,name:'222'},{id:3,name:'李四'},{id:1,name:'张三'}]
arrayObjectDeDuplication(data,'id')
输出结果为:
[{id:1,name:'222'},{id:3,name:'李四'}]