object-path-resolve

1.0.6 • Public • Published

object-path-resolve

A 200b (gzipped) utility function to resolve object properties with string paths

API

resolve(obj: Object, path: String)

Retrieve a value from the obj based on the path (accepts dot and bracket notation)

Usage

import resolve from 'object-path-resolve'
 
const obj = {
  prop: { name: 'John' },
  arr: [
    'one', 'two', 'three'
  ]
}
 
resolve(obj, 'prop.name') // => 'John'
resolve(obj, 'prop.age') // => undefined
resolve(obj, 'arr[1]') // => 'two'

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i object-path-resolve

Weekly Downloads

1

Version

1.0.6

License

MIT

Unpacked Size

152 kB

Total Files

16

Last publish

Collaborators

  • johnsylvain