here is a sample example where there are two arrays and we have a merge() to which we pass the arrays. the merge() should return the merged array such that it should merge the objects which have same name.
let arr1 = [
{
name: "Person1",
age: 20
},
{
name: "Person2",
age: 30
}
]
let arr2 = [
{
name: "Person1",
email: "person1@mail.com"
},
{
name: "Person3",
age: 25
}
]
arr3 = merge(arr1, arr2)
output :
arr3 should be :
[
{
name: "Person1",
age: 20,
email: "person1@mail.com"
},
{
name: "Person2",
age: 30
},
{
name: "Person3",
age: 25
}
]