-6
rated 0 times
[
0]
[
6]
/ answers: 1 / hits: 17185
/ 7 Years ago, thu, february 16, 2017, 12:00:00
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);
More From » lodash