keyarray-set

set nested properties with key arrays

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
keyarray-set
001.0.18 years ago9 years agoMinified + gzip package size for keyarray-set in KB

Readme

var set = require('keyarray-set')
var assert = require('assert')

var anObject = {
  a: {
    b: {}
  }
}

assert(set(anObject, ['a', 'b', 'c'], 'new value') === 'new value')

assert(anObject.a.b.hasOwnProperty('c') === true)

assert(anObject.a.b.c === 'new value')

assert.throws(function () {
  set(anObject, ['nonexistent', 'key'], 'another value')
}, TypeError)