-2
const arr1 = ["a", "b", "c", "d", "e"];
const arr2 = ["b", "d"];

I need to do something which remove "b" and "d" from arr1. Of course I need to remove elements from arr1 which exist in arr2 too.

1
  • what do you mean with "remove"? keep the same array without common items? Commented May 1, 2020 at 18:26

1 Answer 1

2

Try using filter + includes:

const arr1 = ["a", "b", "c", "d", "e"];
const arr2 = ["b", "d"];

let result = arr1.filter(el => !arr2.includes(el));
console.log(result);

Sign up to request clarification or add additional context in comments.

1 Comment

Yup it's woring, but give me some time I need to test it in my code case :D

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.