I have a javascript object that I would like to update with data from another object. I want to add new things from the new object, update old things using the new object and leave alone anything in the old object that is not in the new object. (Example at the bottom)
I have tried various ways but they either overwrite the object completely or they do not cascade without manually writing out loops for objects in objects in objects, etc.
I have also thought about a recursive function that will iterate over the properties, check if it has another object inside itself and if it does call itself all while updating the object. (have not written it, in hopes of something cleaner)
var obj1 = {id:1, name:"asdf", info:{first:3, second:{deeper:3} } };
var obj2 = {id:1, info:{first: 3, second:{deeper:5, new_deeper:6}, third:7}, new_info:7};
I would like to make it so obj1 be equivalent to:
{id:1, name:"asdf", info:{first:3, second:{deeper:5, new_deeper:6}, third:7}, new_info:7};
Thank you in advance!