I am struggling with filtering values from a single-dimensional array based on id matches in an array of objects.
array1 = [1, 3, 15, 16, 18];
array2 = [
{ id: 1, dinner : pizza },
{ id: 15, dinner : sushi },
{ id: 18, dinner : hummus }
]
My goal is to remove values from array1 that don't have a matching id in array2.
While I know how to filter two single-dimensional arrays, I'm having trouble adapting the code for this scenario involving an array of objects.
const array1 = array1.filter(id => array2.includes(id));
If anyone has any insight or suggestions, please share them. Thank you!