I'm attempting to filter info based on a favorite.userId. This is what I'd want, however throughout my experiment, I got an empty array.
I'm attempting to map the favorite as indicated below. favorite.userId, and filtering it with user to retrieve data with the same user Id or the inputted data. Please let me know, or I'll clarify what I'm talking about.
const data = [{
name: "Alif",
favorites: [{
_id: "60fe705efc8be22860620d3b",
userId: "60eaa1b020fa782758751285",
username: "Alif",
createdAt: "2021-07-26T08:20:46.522Z",
},
{
_id: "60fe125efc8be22860620d3b",
userId: "60eaa19820fa782758751285",
username: "Alif",
createdAt: "2021-07-26T08:20:46.522Z",
},
],
}, ];
const user = {
id: "60eaa1b020fa782758751285",
};
const favoriteUser = data.map(({
favorites
}) => {
return favorites.map((favorite) => {
return favorite.userId;
});
});
const wishlist = data.filter(() => {
return favoriteUser == user.id;
});
console.log(wishlist);
