I have an array
const dataitems = [
{name:'test1', id:1},
{name:'test2', id:2},
{name:'test3', id:3}
]
const compares = [1,3]
So i want only to get the values of dataitems which id's are contained in compares array values
so at the end i expect to have a final array as
const ffinaldataitems = [
{name:'test1', id:1},
{name:'test3', id:3}
]
which excludes the id 2
So i have tried the following but am stuck
let finaldataitems = []
dataitems.forEach(item=>{
if(item.id ) //stuck on how to check and push to the array
})
How do i proceed