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


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
},


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM