SOURCE

let arr = [
    { name: '张三' },
    { name: '张三' },
    { name: '李四' },
];

// 方式一
let map1 = new Map();
let res1 = arr.reduce((pre, cur) => {
    if (!map1.has(cur.name)) {
        map1.set(cur.name, true)
        pre.push(cur)
    }
    return pre;
}, [])
console.log(res1)

// 方式二
let map2 = new Map();
let res2 = arr.filter((item) => {
    if (!map2.has(item.name)) {
        map2.set(item.name, true)
        return item;
    }
})

// 简化方式二
let map3 = new Map();
let res3 = arr.filter((item) => !map3.has(item.name) && map3.set(item.name, true))
console.log(res3)
console 命令行工具 X clear

                    
>
console