去重-数组中对象属性重复的数据

// 去除id相同的数据

const arr = [{id:1,name:'ming'},{id:2,name:'ming2'},{id:1,name:'ming'}]
const newArr = arr.reduce(function (tempArr, item) {
if (tempArr.findIndex((ele) => ele.id === item.id) === -1) {
tempArr.push(item)
}
return tempArr
}, [])

 



posted @ 2023-02-02 11:31  天官赐福·  阅读(31)  评论(0编辑  收藏  举报
返回顶端