score:2

Accepted answer

First off, you'll have to make sure if the ID types are correct. Users has Number type for IDs but attendingUsers has String type.

Let's say they're both the same type for the code below (I'm going with string).

You can turn the attendingUsers array into an array of strings with:

const attendingUsersIds = attendingUsers.map(attendingUser => attendingUser.id)

Then match the ids with:

const matchedUsers = users.filter(user => attendingUsersIds.includes(user.id))

If they're intended to not be the same type, you can use user.id.toString() to turn the Number into a String or parseInt(attendingUser.id) to turn the String into a Number.

score:2

We can use Array.map to create a new array of users, with a property isAttending added to each user.

We determine if they are attending by using Array.some to search for any matching attendee with the same id.

const users = [
    {
        id:1,
        name:"John",
        mail:"aaa@gmail.com",
    },
    {
        id:2,
        name:"Joe",
        mail:"bbb@gmail.com",
    },
    {       
        id:3,
        name:"Alice",
        mail:"ccc@gmail.com",
    }
]

const attendingUsers = [
    {
        id:"1",
        name:"John",
        mail:"aaa@gmail.com",

    },
    {
        id:"2",
        name:"Joe",
        mail:"bbb@gmail.com",
    }
] 

const result = users.map(user => { 
    return { ...user, isAttending: attendingUsers.some(({id}) => id == user.id) };
});
console.log("Users (with attending property):", result);


Related Query

More Query from same tag