I've an object as below:
default = {
name: "",
details: {
age: "",
place: ""
country: ""
},
contact: {
email: null,
phone: null
}
}
Now, I've another object as:
data = {
name: "Abc",
details: {
age: "27,
},
contact: {
email: "abc@xyz.com"
}
}
Want to achieve:
result = {
name: "Abc",
details: {
age: 27,
place: ""
country: ""
},
contact: {
email: "abc@xyz.com",
phone: null
}
}
Now, I want to get the values from data and put it in default. Currently I'm checking if the key exists, then assign value, else keep default. But it's a long process. Is there a JS helper function or something that I can use for this?
Object.assign(default, data) is only copying the property values and not going deep.