数组对象去重 、两个数组对比去除相同项

this.choiceJson = []
                let arr2 = this.choiceJson.filter((alone, index) => {
                    let arraids = []
                    this.choiceJson.forEach((item, i) => {
                        arraids.push(item.productId)
                    })
                    return arraids.indexOf(alone.productId) === index
                })
                this.choiceJson = arr2

数组比较去重

uniq (arr) {
let temp = []
let index = []
// let array = [...arr, ...this.selectNode]
let array = [...this.selectNode, ...arr]
let l = array.length
for (var i = 0; i < l; i++) {
for (var j = i + 1; j < l; j++) {
if (array[i].id === array[j].id) {
i++
j = i
}
}
temp.push(array[i])
index.push(i)
}
return temp
},
原文地址:https://www.cnblogs.com/taochengyong/p/12125462.html