deep-set-in
Sets the value at path of object and array tree
Installation
npm install deep-set-in
Usage
Set property in an object
var deepSetIn = var obj = one: two: three: 'test' // { one: { two: { three: 'works' } } }
Set property in an array
var deepSetIn = var obj = one: two: id: 'test id' val: 'test val' // { one: { two: [{ id: 'test id', val: 'works' }] } }
Set property in an array with custom comparator
var deepSetIn = var obj = one: two: id: 1 val: 'test val' var { return a > b;}; // { one: { two: [{ id: 1, val: 'works' }] } }
Arguments
deepSetIn(obj, path, value, options)
obj - Object
: The original object.path - Array
: The property path, array with keys.value - *
: The new object with set value or undefined.options - Object
: The options object.options.immutable - Boolean
: Specify modify original object or return modified one.options.create - Boolean
: Specify creating of new an object or array if it is not exist.
Tests
npm test
License
MIT