Given the following array
[60, 1456]
How can I determine which items in this object do not have a corresponding id to the numbers in the array?
[
{id: 60, itemName: 'Main Location - Cleveland'},
{id: 1453, itemName: 'Second Location - Cleveland'},
{id: 1456, itemName: 'Third Location - New York'}
]
>Solution :
Use filter() combined with includes() to check if the id does not (!) exists in the ids array:
const ids = [60, 1456];
const data = [
{id: 60, itemName: 'Main Location - Cleveland'},
{id: 1453, itemName: 'Second Location - Cleveland'},
{id: 1456, itemName: 'Third Location - New York'}
];
const res = data.filter(({ id }) => !ids.includes(id));
console.log(res);