hey stackoverflow lets say I have an array such as this and an object displayed as below.
['first', 'name']
[{id: 'first'},{id: 'name'},{id: 'last'}]
I want my new object to be filtered out and return
[{id: 'first'}, {id: 'name'}]
How would I go about doing this in javascript?
>Solution :
Use Array.filter and set the condition to whether the array contains the item’s id property:
const a = ['first', 'name']
const arr = [{id: 'first'},{id: 'name'},{id: 'last'}]
const res = arr.filter(e => a.includes(e.id))
console.log(res)