I have a question about the two objects above:
const object1 = { issues: { global: 'a great string!' } };
const object2 = { issues: { cooldown: 'oh well, another message!' } };
For the purpose of my code, I would need to merge everything but keep the hierarchy between the properties. Like this:
Object.assign(object1, object2);
console.log(object1);
// expected output: { issues: { global: 'a great string!', cooldown: 'oh well, another message!' } }
Except that the problem is that the Object.assign()
works such that it will overwrite the previous property (here global
) to keep only the last property (here cooldown
). Like this:
Object.assign(object1, object2);
console.log(object1);
// real output: { issues: { cooldown: 'oh well, another message!' } }
My question is then simple: how do we get the expected result? I guess it's not as simple as a simple Object.assign()
, but precisely: how? Knowing that obviously I took here an example and that, in reality, impossible to know in advance which properties will arrive...
Thanking you for help