I have two array object array1 and array2, I want to merge the data on the basis of the key name
array1= [
{
name:"adam",
data:[
]
},
{
name:"eve",
data:[
[
"child"
],
[
"secondchild"
]
]
}
]
array2= [
{
name:"adam",
data:[
[
"thirdchild"
],
[
"fourthchild"
]
]
},
{
name:"eve",
data:[
]
}
]
the output should be
result= [
{
name:"adam",
data:[
[
"thirdchild"
],
[
"fourthchild"
]
]
},
{
name:"eve",
data:[
[
"child"
],
[
"secondchild"
]
]
}
]
I have been able to get the object index but I am not able to push the array inside data, I am not able to write down the code here as I am working on a virtual machine. any hint or help would be appreciated.
I am running a map of array1 and inside it, I am running another map of array 2 but I don't think its the optimized way of doing
array1.map(el => {
array2.map(es => {
if(el.name === es.name){
/// here I am doing the logic , is there any optimized ways
}
})})