Dealing with comparing an array of objects with a nested array to find the differences has been a challenge for me. The filtering methods I've attempted have only resulted in either returning the entire array or producing undefined results.
Let's take a look at what my data actually consists of:
const groups = [
{
name: "Team Rocket",
managerId: "abc",
members: ["1"]
},
{
name: "The Breakfast Club",
managerId: "def",
members: [],
}
];
const users = [
{
name: "Jessie",
userId: "1"
},
{
name: "John",
userId: "2"
}
]
In this scenario, the goal is to compare the userId from the users array with the items within the members array. Ultimately, the desired outcome is to obtain John's data.
Here's an example of what I've attempted:
const userWithNoGroup = users.filter((user) => {
return !groups.some((group) => {
return user.userId === group.members;
});
});
However, the current implementation returns all users instead of the expected result. It appears that the issue lies in the fact that 'members' is a nested array, but I'm uncertain about how to address this problem.