Let's say I want to assign a value similar to this:
x.label1.label2.label3 = someValue;
// or equivalently:
x['label1']['label2']['label3'] = someValue;
This works as long as it x.label1.label2is determined, but otherwise a reference error will be used. This, of course, makes sense. But is there an easy way to assign this anyway where it just creates the necessary nested objects?
So for example, if xequal { label1: {}, otherLabel: 'otherValue' }, I want to update xto become{ label1: { label2: { label3: someValue } }, otherLabel: otherValue }
I think I could write a function myself, but is there a language function or a standard library function that does this?
source
share