const arr = [
{
"id":"1",
"name":'zhangsan'
},
{
"id":"2",
"name":"lisi"
},
{
"id":"1",
"name":"wangwu"
}
]
方法一:
const peon = arr.reduce((pre, cur) => {
const index = pre.findIndex(x=>x.id === cur.id)
if(index <0){
pre.push(cur)
}
return pre
}, [])
console.log(peon)
方法二:
const tempArr = []
arr.forEach((item) => {
const index = tempArr.findIndex(x=>x.id === item.id)
if(index <0){
tempArr.push(item)
}
})
console.log(tempArr);