getsetdeep

Get and set nested variables of an object, includes support for Backbone Models

Get Set Deep

Get and set nested variables of an object, includes support for Backbone Models

  1. Install Node.js
  2. npm install --save getsetdeep
  1. See Browserify
// Import 
var getsetdeep = require('getsetdeep')
 
// Prepare 
var obj = {
    a: {
        b: {
            c: 3
        }
    }
}
 
// Get 
getsetdeep.getDeep(obj, 'a.b.c')     // returns 3 
getsetdeep.setDeep(obj, 'a.b.c', 4)  // returns 4 
getsetdeep.getDeep(obj, 'a.b.c')     // returns 4 
  • setDeep also has a fourth argument called setOnlyIfEmpty which defaults to false, if specified to true then setDeep will only set the value if the current value is null or undefined
  • We also work with Backbone Models (or rather any model that utilizes an attributes object)

You can discover the history inside the History.md file

Licensed under the incredibly permissive MIT License
Copyright © 2013+ Bevry Pty Ltd
Copyright © 2011-2012 Benjamin Arthur Lupton