How can I merge two objects containing array and other fields using lodash?
For example,
obj1 = {
name: "abc",
hobbies: ["reading","cricket"]
}
obj2 = {
name: "abc2",
hobbies: ["reading","hockey"]
}
_.merge(obj1, obj2)
// output
{
name: "abc2",
hobbies: ["reading","hockey"]
}
this returns an object after merging obj1 into obj2 but without merging the hobbies.
namewithobj2, but not overwritehobbies?obj2. I'm a little confused at the result you want._.mergeisn't part of underscore.js. Where are you getting that from?