Es6, removes the contents of one array from another array

my code has bug, and then I checked to write = = as =

.

A [1,2,3,4,5,6,7]
B [2,3,4]

after deletion

A [1,5,6,7]



    this.selectRightTableData.forEach(item => {
      this.rightTableData.splice(this.rightTableData.findIndex(v => v.id = item.id), 1)
    })

  

after repair, judge according to an attribute of the object; whether it is the same

  
      

    this.selectRightTableData.forEach(item => {
      this.rightTableData.splice(this.rightTableData.findIndex(v => v.id == item.id), 1)
    })
  

judge by memory address

this.selectLeftTableData.forEach(item => {
      this.leftTableData.splice(this.leftTableData.indexOf(item), 1)
    })
Mar.03,2021

feel that there is no new array, yet, and then it is convenient for indexOf to add push to the new array

    const a = [1,2,3,4,5], b = [1,2],c = [];
    a.forEach( v => {
      if(b.indexOf(v) === -1) c.push(v)
    })

let A=[1,2,3,4,5,6,7];
let B=[2,3,4];
let newB=[];
for(var i=0,lenA=A.length;i<lenA;iPP){
    for(var b=0,lenB=B.length;b<lenB;bPP){
        if(A[i]!=B[b]){
            newB.push(B[b])
        }
    }
}

this can also achieve the effect you want

Menu