I have two arrays of objects that share a property with the same name (userId
), but have different lengths. Here is a simple example:
const arr1= [
{
userId: "1",
name:"Tommy",
hobbies:"fighting"
},
{
userId: "16",
name:"Kino",
hobbies:"skating"
}
];
const arr2= [
{
userId: "1",
story:"Big fight"
},
{
userId:"16",
story:"big momentum"
}
];
My ideal outcome would be to have one array which combines both objects that match in property with userId
(and all objects that match in property) and keeps all of the properties of both.
I´ve tried using concat
and then filtering, but to no avail. Any clues or suggestion on how this can be accomplished?