I have two almost identical arrays of objects, the only difference between them is that the first array consists of inner arrays with objects having a text1 attribute, and the second array has text2 property instead. Each array contains 800 objects with same keys 1, 2, 3, 4 ....
How can I merge these two arrays? I tried with push function but got only the first array. Is there some other way to merge two arrays like reduce, filter or some other function?
let arr1 = [{
"1": [{
"text1": "Some text 1",
"englishName": "Name 1",
"number": 1,
},
{
"text1": "Some text 2",
"englishName": "Name 2",
"number": 2,
}
]
},
{
"2": [{
"text1": "Some text 3",
"englishName": "Name 3",
"number": 3,
},
{
"text1": "Some text 4",
"englishName": "Name 4",
"number": 4,
}
]
}
]
let arr2 = [{
"1": [{
"text2": "Some new text",
"englishName": "Name 1",
"number": 1
},
{
"text2": "Some new text 2",
"englishName": "Name 2",
"number": 2,
}
]
},
{
"2": [{
"text2": "Some new text 3",
"englishName": "Name 3",
"number": 3,
},
{
"text2": "Some new text 4",
"englishName": "Name 4",
"number": 4,
}
]
}
]
i need to merge in one array and concat text2 to first array like this
let mergearray = [
{
"1": [
{
"text1": "Some text 1",
"text2": "Some new text 1",
"englishName": "Name 1",
"number": 1,
},
{
"text1": "Some text 2",
"text2": "Some new text 2",
"englishName": "Name 2",
"number": 2,
}
]
},
{
"2": [
{
"text1": "Some text 3",
"text2": "Some new text 3",
"englishName": "Name 3",
"number": 3,
},
{
"text1": "Some text 4",
"text2": "Some new text 4",
"englishName": "Name 4",
"number": 4,
} ] } ]
How compare keys of arrays?
text2fields to be converted totext1?