Hello everyone, I am facing an issue when trying to combine two nested parent arrays of objects. I want to merge only the children items that have the same group parent. Here is my scenario: I have two arrays
var arr1 = [{group: "a", items: ["a","b","c","d"]}, {group: "b", items:["k","l","m"]}];
var arr2 = [{group: "b", items: ["o","p","q","r"]}, {group: "c", items:["1","2","3","4"]}]
I need to merge these two arrays. If the second array has the same parent group, I want to simply add its items to the existing group, giving this expected result:
[
{
group: "a",
items: ["a","b","c","d"]
},
{
group: "b",
items: ["k","l","m","o","p","q", "r"]
},
{
group: "c",
items: ["1","2","3","4"]
},
]
In this case, arr1 and arr2 both have the same b group. Only the items will be combined in this scenario. I have tried searching everywhere for a solution but I'm still unable to figure it out. Your assistance would be greatly appreciated. Thank you in advance.