D
D
Damen Damen2018-02-15 16:20:28
JavaScript
Damen Damen, 2018-02-15 16:20:28

How to compare arrays?

There are two arrays, let's say A[1,2,3,4,5,6,7,8,9,0] and B[2,1,0,5,4].
How to remove elements from array B from array A?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-02-15
@uWotM8

A.filter(n => !B.includes(n))
or, if you really need to modify the original array:

for (let i = A.length; i--;) {
  if (B.includes(A[i])) {
    A.splice(i, 1);
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question