I know similar questions have been posted but they never seems to target the same problem.
I want to remove Objects contained in the second array (itemsToRemove
) from the first array (allItems
).
allItems = [{x:1, y:2}, {x:1, y:1}, {x:4, y:1}]
itemsToRemove = [{x:1, y:2}]
result = [{x:1, y:1}, {x:4, y:1}]
I've tried many ways, but it somehow fails at the find()
condition
const result = allItems.filter((itemFromAllItems ) => {
return !itemsToRemove.find( itemToRemove => {
return itemFromAllItems.x === itemToRemove.x && itemFromAllItems.y === itemToRemove.y
})
})