(Maintained fork of Dotty) Access properties of nested objects using dot-path notation

Downloads in past


200.1.110 years ago10 years agoMinified + gzip package size for dotty-bindable in KB


(MAINTAINED Version) (Works on 0.6 - 0.11) Previous version not tested but should work
  • note: After Dotty fell into the hole of forgotten projects, I have uploaded this module. I will work to get the current pull requests merged into my branch as well as improve any existing functionality as best I can without breaking backwards compatibility with Dotty.
Dotty (Maintained as "dotty-bindable" on NPM) build status
Access properties of nested objects using dot-path notation.


Dotty makes it easy to programmatically access arbitrarily nested objects and their properties.


Here's a link to the npm page.
npm install dotty


Also see the documentation and example.
var dotty = require("dotty");

var object = {
  a: {
    b: {
      x: "y",
    c: {
      x: "z",

console.log(dotty.exists(object, "a.b.x")); // true
console.log(dotty.exists(object, ["a", "b", "x"])); // true
console.log(dotty.exists(object, "a.b.z")); // false
console.log(dotty.exists(object, ["a", "b", "z"])); // false

console.log(dotty.get(object, "a.b.x")); // "y"
console.log(dotty.get(object, ["a", "b", "x"])); // "y"
console.log(dotty.get(object, "a.b.z")); // undefined
console.log(dotty.get(object, ["a", "b", "z"])); // undefine

dotty.put(object, "a.b.hello", "hi");
dotty.put(object, ["a", "c", "yo"], "sup");

console.log(, "a.b.*"));
console.log(, ["a", "b", "*"]));
console.log(, "a.*.x"));
console.log(, ["a", "*", "x"]));
console.log(, ["a", "*", /..+/]));

console.log(dotty.remove(object, "a.b.x"));
console.log(dotty.remove(object, "a.b.y"));

console.log(dotty.deepKeys(object, {leavesOnly: true}));
console.log(dotty.deepKeys(object, {leavesOnly: true, asStrings: true}));


Binding and Currying

Note please read below for the one Caveat of this new feature, which affects put.
var obj = 
  user: {
    name: {
      primary: "John",
      surname: "Doe"
    age: 26,
    location: {
      city: "New York",
      region: "New York",
      region_abbrev: "NY",
// Dotty GET - supports dot and array notation and single string mixed in, as long as arguments length > 2
var user = dotty.get.bind(null, obj, ['user']);

var name
// name can either inherit from user, or from obj lets see both in action

name = user.bind(null, ['name']);

console.log('Curried from user object')

console.log('Curried from top level object');
name = dotty.get.bind(null, obj, ['user'], 'name');

console.log('Accessed via return name as an object and just accessing its properties.');

console.log('Let try make a function to dynamically return the city even if it is changed from somewhere else in the program');

console.log('Curry from top level object');
var city = dotty.get.bind(null, obj)
                .bind(null, 'user.location')
                .bind(null, 'city');

// Nottice we used 3 binds, this does not really matter, it could have been one, it is just to prove the point of currying.

console.log('My city is ' + city() );
console.log('someones changing my city'); = 'Albany';
console.log('My city is now ' + city() );

// The Same applies to PUT EXISTS REMOVE SEARCH
// HOWEVER one caveat does exist for PUT, the last argument will never be deconstructed, it is strictly the value.

console.log('Now showing PUT caveat');
// So in the syntax
obj1 = {a: { b: {c: {d: { e: 1}}}}}
var ans = dotty.get(obj1, 'a', 'b', 'c', ['d', 'e']);
// the last item is an array and is deconstructed to be

dotty.put(obj1, 'a', 'b', 'c', ['d', 'e']);
// The last item is strictly a value and is not deconstructed
console.log(dotty.get(obj1, 'a', 'b', 'c'));
// output: ['d', 'e']
// Thus this is essentially equal to
obj1['a']['b']['c'] = ['d', 'e'];


3-clause BSD. A copy is included with the source.