I have a single dimensional and an array of Objects
array1 = [1, 3, 15, 16, 18];
array2 = [
{ id: 1, dinner : pizza },
{ id: 15, dinner : sushi },
{ id: 18, dinner : hummus }
]
I'm trying to remove values from array1 that are not in array2 based on the id.
I know how to remove in two single dimensional arrays but I'm unable to modify the code to remove when array2 is an array of Objects.
const array1 = array1.filter(id => array2.includes(id));
Any help would be appreciated.
reducewould perform better to avoid two passes. Elaborating below: