const likedUsers = [{
id: "1"
},
{
id: "2"
}
]
const needToFilter = [{
id: "1",
userInfo: "info"
}, {
id: "2",
userInfo: "info"
},
{
id: "3",
userInfo: "info"
}
]
likedUsers.forEach(item => needToFilter.filter(needToFilter => {
return needToFilter.id !== item.id
}));
console.log(users);
I have two arrays like that and if needToFilter array's user id exist in likedUsers array it need to be gone.
Filtered array be like :
needToFilter => [{id:"3",userInfo:"info"}]
I tried forEach
and map
but result is the same. I know there is another way but i can't figure out how.
Thank you all guys.
Edit : All the answers works great in my case but i used Set approach to fix my problem.