1๐
โ
try filter and find methods :
let result =products.filter(prod=>{
return !deletedProducts.find(dprod=>{
return dprod.id===prod.id;
})
})
let products = [{
id: 1,
name: 'Box'
},
{
id: 2,
name: 'Lamp'
}
]
let deletedProducts = [{
id: 1,
name: 'Box'
}]
let result = products.filter(prod => {
return !deletedProducts.find(dprod => {
return dprod.id === prod.id;
})
})
console.log(result)
0๐
try this comparer function and filter. (reference by array of element "id" on this exmaple)
let products = [
{
id: 1,
name: 'Box'
},
{
id: 2,
name: 'Lamp'
}
]
let deletedProducts = [
{
id: 1,
name: 'Box'
}
]
function comparer(otherArray){
return function (current) {
return otherArray.filter(function(other) {
return other.id === current.id
}).length===0;
}
}
var result=products.filter(comparer(deletedProducts ));
console.log(result);
Source:stackexchange.com