对象数组去重,可以使用 Map 集合,通过对象内的某个属性进行去重。做个笔记,记录一下。
toAudit() {
const arr = [{
id: 1,
fruits: '香蕉',
attr: f001,
},
{
id: 2,
fruits: '苹果',
attr: f002,
},
{
id: 3,
fruits: '香蕉',
attr: f001,
},]
const map = new Map();
const newArr = arr.filter(key = >!map.has(key.attr) && map.set(key.attr, 1));
console.log(newArr);
},