Skip to content
forked from 75lb/object-get

Access nested property values at any depth with a simple expression.

License

Notifications You must be signed in to change notification settings

prepair/object-get

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

view on npm npm module downloads Build Status Dependency Status js-standard-style

object-get

Access nested property values at any depth with a simple expression.

Example

const objectGet = require('object-get')

const colour = objectGet(mammal, 'fur.appearance.colour')
const text = objectGet(el, 'children[2].children[1].children[1].textContent')

Helps avoid long logical expressions like:

const colour = mammal && mammal.fur && mammal.fur.appearance && mammal.fur.appearance.colour

objectGet(object, expression) ⇒ *

Returns the value at the given property.

Kind: Exported function

Param Type Description
object object the input object
expression string the property accessor expression.

Example

> objectGet({ animal: 'cow' }, 'animal')
'cow'

> objectGet({ animal: { mood: 'lazy' } }, 'animal')
{ mood: 'lazy' }

> objectGet({ animal: { mood: 'lazy' } }, 'animal.mood')
'lazy'

> objectGet({ animal: { mood: 'lazy' } }, 'animal.email')
undefined

© 2015-16 Lloyd Brookes <[email protected]>. Documented by jsdoc-to-markdown.

About

Access nested property values at any depth with a simple expression.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%