I am currently working with two arrays named totalArray
and selectionArray
. These arrays have dynamic values, but for the sake of example I have provided sample arrays below. My goal is to remove objects from totalArray
based on their id rather than index. This is because each page only displays five values, and removing by index would affect other pages as well due to consistent indexing across pages. Is there a method besides using splice to achieve this, or is there another solution available?
totalArray = [
{id: 1, city: 'LONDON'},
{id: 2, city: 'PARIS'},
{id: 3, city: 'NEW YORK'},
{id: 4, city: 'BERLIN'},
{id: 5, city: 'MADRID'},
{id: 6, city: 'ROME'},
{id: 7, city: 'DUBLIN'},
{id: 8, city: 'ATHENS'},
{id: 9, city: 'ANKARA'},
{id: 10, city: 'MOSCOW'},
]
selectionArray = [
{id: 6, city: 'ROME'},
{id: 7, city: 'DUBLIN'},
{id: 8, city: 'ATHENS'},
{id: 9, city: 'ANKARA'},
{id: 10, city: 'MOSCOW'},
]
selectionArray.forEach((item, i) => {
totalArray.splice(item.id, 1);
});