-2

I have an array like this:

let arr = ['liverpool', 'arsenal', 'man utd', 'chelsea', 'tottenham', 'crystal palace', 'madrid', 'barcelona'];

and I want to remove items, let's say 'arsenal' and 'chelsea', but this needs to be dynamic.

I have tried the following, where items is an array but unfortunately it didn't work:

function removeItems(items) {
   arr.filter(item => {
      return !arr.includes(items)
   });
}

removeItems(['arsenal', 'chelsea']);
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
peter flanagan
  • 9,195
  • 26
  • 73
  • 127

1 Answers1

2

I think what you are trying to do is this:

function removeItems(items) {
   return arr.filter(item => {
      return !items.includes(item)
   });
}

const newArr = removeItems(['arsenal', 'chelsea']);
Chen.so
  • 173
  • 7