I'm trying to use Lodash to merge object A into object B, but the trouble I am having is that object A has some undefined values and I want these to be copied over to object B.
Lodash docs for _.merge() says:
"Recursively merges own enumerable properties of the source object(s), that don't resolve to undefined into the destination object."
Is there another function that can do this, or can it be easily overwritten?
EDIT A:
Sample input:
A = {
name: "Bob Smith",
job: "Racing Driver",
address: undefined
}
B = {
name: "Bob Smith",
job: "Web Developer",
address: "1 Regent Street, London",
phone: "0800 800 80"
}
Expected Output
B = {
name: "Bob Smith",
job: "Racing Driver",
address: undefined,
phone: "0800 800 80"
}
EDIT B:
Just to confirm, it needs to be a "deep" merge. object may contain nested objects.
Easiest would be to use 3rd package for this https://github.com/unclechu/node-deep-extend which goal is only deep merging and nothing else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With