Wednesday, 6 October 2021

Arrays filtering in MERN Mongo , express, react and node

let array1=[1,2,3];
let array2=[1,2,4,5,6,7,7,4,3,2,1,4,5,5,2,3,3,1,2,9,8,6,4,3,2,7,1] 

remove array1 element from array2,expected out=[4,5,6,7,7,4,4,5,5,9,8,6,4,7]

 

Solution : 

let array1=[1,2,3];
let array2=[1,2,4,5,6,7,7,4,3,2,1,4,5,5,2,3,3,1,2,9,8,6,4,3,2,7,1];


let output = array2.filter((item)=> !array1.includes(item))

console.log(output);