3.0.1 • Published 8 years ago

get-in v3.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
8 years ago

get-in

get value of nested associative structure given array of keys

inspired by clojure.core/get-in.

code stolen from micro-js/get-prop.

install

with npm, do:

npm i --save get-in

usage

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'

api

getIn(object, path, default)

  • object - object to retrieve value from
  • path - array specifying path
  • default - default value if none found

Returns: value

license

ISC