get-in
Version:
get value of nested associative structure given array of keys
43 lines (26 loc) • 766 B
Markdown
get value of nested associative structure given array of keys
inspired by [clojure.core/get-in](http://clojuredocs.org/clojure_core/1.2.0/clojure.core/get-in).
code stolen from [micro-js/get-prop](https://github.com/micro-js/get-prop).
with [npm](http://npmjs.org), do:
```
npm i --save get-in
```
```
var getIn = require('get-in')
var obj = { foo: { bar: 'baz' } }
getIn(obj, ['foo', 'bar']) // => 'baz'
getIn(obj, ['foo']) // => { bar: 'baz' }
getIn(obj, ['ping']) // => undefined
getIn(obj, ['ping'], 'pong') // => 'pong'
```
- `object` - object to retrieve value from
- `path` - array specifying path
- `default` - default value if none found
**Returns**: value
ISC