Having an issue with merging nested JSON Array objects.
var o1 = {
"customerId": "ABC",
"questions": [
{
"status": 2,
"isBookmarked": 0,
"questionId": 1
}
]
}
var o2 = {
"customerId": "ABC",
"questions": [
{
"status": 1,
"isBookmarked": 1,
"questionId": 2
},
{
"status": 1,
"isBookmarked": 1,
"questionId": 3
}
]
}
The question array needs to merge together. If the same question is found in both objects then it should take 2 object values (o2 - object).
I tried to do it like this:
const o3 = Object.assign({}, o1, o2);
Here is the link to reproduce - https://jsfiddle.net/y97afosd/
Expected output -
{
"customerId": "ABC",
"questions": [
{
"status": 2,
"isBookmarked": 0,
"questionId": 1
},
{
"status": 1,
"isBookmarked": 1,
"questionId": 2
},
{
"status": 1,
"isBookmarked": 1,
"questionId": 3
}
]
}
Can someone help with it?