I have following object array:
var arr = [
{
id : "a1",
guid : "sdfsfd",
...
value : "abc",
status: false
},
{
id : "a2",
guid : "sdfsfd",
...
value : "def",
status: true
},
...
]
I have this object:
var obj = {
id : "a1",
guid : "sdfsfd",
...
value : "xyz",
status : true
}
I need to replace the object in the array with this object where the "id" is same. So the resulting array will be:
var arr = [
{
id : "a1",
guid : "sdfsfd",
...
value : "xyz",
status: true
},
{
id : "a2",
guid : "sdfsfd",
...
value : "def",
status: true
},
...
]
Additionally I need to add this object to the array if an object with that id doesn't exists.
How to achieve this using minimal lodash code? Looking for something like
arr = _.merge_by_key(arr,obj,"id");