object-path-get

1.0.1 • Public • Published

object-path-get

NPM version Build Status Code Climate Coverage Status Dependency Status devDependency Status

NPM

Description

get values from javascript objects by specifying a path.

by using this library, you can help prevent the following error from occurring:

Cannot read property 'foo' of undefined

NOTE: I've re-written / used this function so many different times, I decided to publish it as a module.

Getting Started

Install the module with: npm install --save object-path-get

var getPath = require('object-path-get');
var obj = { foo: { bar: 'baz' } };
getPath(obj, 'foo.bar'); // result: "baz"
getPath(obj, 'foo.invalidKey', 'cool'); // result: "cool"
getPath(obj, 'foo|bar', null, '|'); // result: "baz" (with different delimiter)
getPath(obj, ['foo', 'bar']); // result "baz" (with array path)

Links

Contributors

Thanks goes to these wonderful people (emoji key):



💻 📖 💡

danigb

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

License

Copyright (c) 2014 skratchdot
Licensed under the MIT license.

Readme

Keywords

Package Sidebar

Install

npm i object-path-get

Weekly Downloads

68

Version

1.0.1

License

MIT

Unpacked Size

15 kB

Total Files

9

Last publish

Collaborators

  • skratchdot