-2

If I have an array A = [1, 2, 3, 4, 5] and B = [3, 4, 5] I want to return a new array with values [1, 2]. remove same value.

1 Answers1

2

Using Array.prototype.includes, you can check if B contains A item or not.

And using Array.prototype.filter, you can get the filtered values which are not included in array B.

const A = [1, 2, 3, 4, 5];
const B = [3, 4, 5];

const output = A.filter((item) => !B.includes(item));
console.log(output);
Derek Wang
  • 10,098
  • 4
  • 18
  • 39