Non-destructively set a nested property, given its path
$ npm install @f/set-prop
varsetProp=require('@f/set-prop')varobj={a: {b: 1}}varnewObj=setProp('a.b',obj,2)obj.a.b===1newObj.a.b===2obj!==newObjpath- The path (specified as array or dotted string) of the property you wish to setobj- The root object you want to set withinvalue- The value you want to assign topathwithinobj
Returns: A new root obj that has path changed to value, and all of the sub-objects in its tree cloned as well.
MIT