Sets a value of a property in an object tree. Missing objects will (optionally) be created.
npm install deep-set
In the browser you can use deepSet with Browserify, RequireJS or as a window global.
var deepSet = require('deep-set')
var obj = { one: { two: { three: 'sad' } } }
deepSet(obj, 'one.two.three', 'yay')
// { one: { two: { three: 'yay' } } }
deepSet(obj, path, value, create)
obj - Object
: The original object.path - String
: The path to traverse, separated by dots.value - *
: The value to set.create - Boolean
: Whether to create missing objects along the waydefault: true
.
npm test
MIT