js对象数组去重

hong1 / 2024-10-21 / 原文

对象数组去重

方法1:

// key为对象的某个字段的key
removeDuplicationData(arr, key) {
    const obj = {}
    arr = arr.reduce((item, next) => {
        obj[next[key]] ? '' : (obj[next[key]] = true && item.push(next))
        return item
    }, [])
    return arr
}