Home

Awesome

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 = require('deep-set-in')

var obj = { one: { two: { three: 'test' } } }

deepSetIn(obj, ['one', 'two', 'three'], 'works')
// { one: { two: { three: 'works' } } }

Set property in an array

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' }] } }

Arguments

deepSetIn(obj, path, value, options)

Tests

npm test

License

MIT