I'm writing a simple Vue app where an Array with Objects should be updated with an incoming object.
I start with this Object:
var arr =
[
{
"mainId": 1,
"parents": [
{
"parent": 1
},
{
"parent": 2
}
]
},
{
"mainId": 2,
"parents": [
{
"parent": 3
}
]
}
]
I want to Update the "parent" Array with the following Object:
var updateArray = {
"mainId": 2,
"parent": 9
}
var updatedArray =
[
{
"mainId": 1,
"parents": [
{
"parent": 1
},
{
"parent": 2
}
]
},
{
"mainId": 2,
"parents": [
{
"parent": 3
},
{
"parent": 9 // <-------------
}
]
}
]
What is the best way to achieve this?