get-in

3.0.1 • Public • Published

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

Package Sidebar

Install

npm i get-in

Weekly Downloads

16

Version

3.0.1

License

ISC

Last publish

Collaborators

  • ahdinosaur