I am facing a scenario where I have two arrays:
"array_one":
[
{
"id": 1,
"name": One
},
{
"id": 2,
"name": Two
}
]
"array_two":
[
{
"id": 1,
"name": Uno
},
{
"id": 3,
"name": Three
}
]
My task involves using Underscore to achieve the following objectives:
Replace all objects in array_one with objects that share the same id from array_two.
Add any objects from array_two to array_one if there isn't already an object with their id present.
The replaced objects should maintain their original position in the array.
Any added objects need to be placed at the end of the array.
As a result, the final array should appear as follows:
"array_final":
[
{
"id": 1,
"name": Uno
},
{
"id": 2,
"name": Two
},
{
"id": 3,
"name": Three
}
]