Sets the value at path of object and array tree
Set property in an objectvar deepSetIn = require('deep-set-in') var obj = { one: { two: { three: 'test' } } } deepSetIn(obj, ['one', 'two', 'three'], 'works') // { one: { two: { three: 'works' } } }
var deepSetIn = require('deep-set-in') var obj = { one: { two: [{ id: 'test id', val: 'test val' }] } } deepSetIn(obj, ['one', ['two', 'id', 'test id'], 'val'], 'works') // { one: { two: [{ id: 'test id', val: 'works' }] } }Set property in an array with custom comparator
var deepSetIn = require('deep-set-in') var obj = { one: { two: [{ id: 1, val: 'test val' }] } } var comparator = function(a, b) { return a > b; }; deepSetIn(obj, ['one', ['two', 'id', 999, comparator], 'val'], 'works') // { one: { two: [{ id: 1, val: 'works' }] } }
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.MIT
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4