Remove entry from array using another array

前端 未结 7 1973
迷失自我
迷失自我 2021-01-25 09:12

Not sure how do to this, so any help is greatly appreciated

Say I have :

const array1 = [1, 1, 2, 3, 4];
const array2 = [1, 2];

Desired

7条回答
  •  走了就别回头了
    2021-01-25 09:32

    You can try the following. Loop through array1 and check if the element of array2 exists on array1 and splice it out.

    const array1 = [1, 1, 2, 3, 4];
    const array2 = [1, 2];
    
    
    for(i=0;i<=array1.length;i++){
    
      for(j=0;j

提交回复
热议问题