let testList = [
{
name: 'zws001',
id: "test_001"
},
{
name: 'zws001',
id: "test_001"
},
{
name: 'zws001',
id: "test_001"
}
]
// let refList = []
// testList.forEach(item => {
// refList.push(item)
// let hash = {}
// refList = refList.reduce((item, next) => {
// console.log('next---',next)
// // 根据 id 去重
// if (!hash[next.id]) {
// hash[next.id] = true
// item.push(next)
// }
// return item
// }, [])
// })
let refList = []
refList.push(...testList)
testList.forEach(item => {
refList.push(item)
refList = refList.reduce((item, next) => {
console.log('next---', next)
// 根据 id 去重
if (!hash[next.id]) {
hash[next.id] = true
item.push(next)
}
return item
}, [])
})
console.log('---refList', refList)
console