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 
console.log(getsetdeep.getDeep(obj, 'a.b.c'));     // 3 
console.log(getsetdeep.setDeep(obj, 'a.b.c', 4));  // 4 
console.log(getsetdeep.getDeep(obj, 'a.b.c'));     // 4 
  • setDeep also has a fourth argument opts for options, currently we support the options:
    • onlyIfEmpty 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 getters get(key) and setters set(attrs,opts), enabling support for Backbone.js models as well as others

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