Is it possible to add nested objects together. I know Object.assign can merge two objects. For example:
const target = { a: 1, b: { c: 2, d: 3 } };
const source = { e: 7, b: { c: 1, d: 5 } };
const returnedTarget = Object.assign(target, source);
returnedTarget = { a: 1, b: { c: 1, d: 5 }, e: 7 }
But is there anyway to add variables C and D rather than overwriting them with the source?
An actual use case example:
[
Character1: {
kills: { value: 10.0, displayValue: "10" },
deaths: { value: 5.0, displayValue: "5" }
},
Character2: {
kills: { value: 20.0, displayValue: "20" },
deaths: { value: 15.0, displayValue: "15" }
},
]
//Expected Result:
[
Merged: {
kills: { value: 30.0, displayValue: "30" },
deaths: { value: 20.0, displayValue: "20" }
}
]