删除在另一个数组中包含的元素:
需要注意的是splice是对数组进行操作,会改变数组,下角标也会改变,在循环中操作时会出现删除错的情况,解决办法是从后往前删除。或者不使用splice使用新建数组添加元素的方法
deleteHasInList(currList: any[], otherList: any[]) {
let i = currList.length
while (i--) {
if (otherList.some((x) => {
return currList[i].scanItemName === x.scanItemName
})) currList.splice(i, 1)
}
}
删除在另一个数组中不包含的元素:
deleteNotInList(currList: any[], otherList: any[]) {
let i = currList.length
while (i--) {
if (!otherList.some((x) => {
return currList[i].scanItemName === x.scanItemName
})) currList.splice(i, 1)
}
}