數組對象去重 、兩個數組對比去除相同項


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