My blog features various articles that users can interact with. Each user has a property called "favorites," which stores an array of their favorite posts. By clicking on the heart icon next to a post, the title of that post gets added to the user's favorites list.
I want to create a section on each user's profile page where they can view all the posts they've added to their favorites. This involves comparing the user's favorites array to the array of all available posts.
userFavoritesArray = ['post1', 'post2', 'post5', ...]
postsArray = [
{
title: 'post1',
desc: 'hello'
},
...
]
For example:
user: {
favorites: ['post1']
}
posts: [
{name: 'post1', desc: 'yo bro'},
{name: 'post2', desc: 'hello im the post2'},
{name: 'post3', desc: 'good morning'}
]
The desired output for this user would be
favorites: [{name: 'post1', desc: 'yo bro'}]