去除一个数组中的相同元素

let resdata=[{id:'1',name:'小花’},{id:'2',name:'小明’},{id:'3',name:'小马哥'},{id:'1',name:'小王'}]
let hash = {};
let newArr = resdata.reduce((item, next) => {
hash[next.benchmarkCode] ? '' : hash[next.benchmarkCode] = true && item.push(next);
return item
}, []);
console.log(newArr)
posted @ 2021-09-17 10:40  白_小白  阅读(83)  评论(0)    收藏  举报