Here I have an array of objects:
listPosts = [
0: {
id = String
}
]
And an object:
user = {
savedPosts = Array (containing array of listPosts[index].id)
}
I practically need to display the savedPosts, with a double iteration where:
user.savedPosts[y] === listPosts[i].id
With a for loop it would looks something like this:
for (let i = 0; i < listPosts.length; i++) {
for (let y = 0; i < user.savedPosts.length; y++) {
if (user.savedPosts[y] === listPosts[i].id)
return console.log('Matched');
}
}
How can I 'translate' this logic by using a filter iteration?
I know there are many other questions out there with similar answers when coming to iterating arrays / objects using filter, but I really cannot get a solution for this issue.
Here some 'related' q&a I found which don't really help in this situation, but may in others:
- How to filter an array from all elements of another array
- How to iterate two array inside React render method
Thank you in advance for your explanations and help.