Skip to content

Instantly share code, notes, and snippets.

@mjgpy3
Created March 3, 2016 19:45
Show Gist options
  • Save mjgpy3/006e92b439b86812a8b2 to your computer and use it in GitHub Desktop.
Save mjgpy3/006e92b439b86812a8b2 to your computer and use it in GitHub Desktop.
Deep property index in JavaScript
var deepProperty = function (properties) {
return function (obj) {
return properties.reduce(function (obj, key) {
return obj[key];
}, obj);
};
};
deepProp(['a', 'b', 'c'])({ a: { b: { c: 42 } }}) // => 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment