Created
March 3, 2016 19:45
-
-
Save mjgpy3/006e92b439b86812a8b2 to your computer and use it in GitHub Desktop.
Deep property index in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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