Home > OS >  Filter Array if elements are in another Array [duplicate]
Filter Array if elements are in another Array [duplicate]

Time:09-22

Trying to figure out the proper syntax on filtering elements out of one array if they belong in another but can't get it right. In the following example I'm trying to remove any elements in array1 that are in array2. Any ideas on how to make it work?

array1.filter( element => array2.includes( element ) ); 

CodePudding user response:

array1.filter( element => !array2.includes( element ) ); 
  • Related