Awesome
object-at
Get object's property according to the path.
Install
$ npm install --save object-at
Usage
For more use-cases see the tests
var at = require('object-at');
var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
at(object, 'a[0].b.c'); // => 3
at(object, 'a[1]'); // => 4
at(['a', 'b', 'c'], 2); // => 'c'
at(); // => undefined
at(['a', 'b', 'c']); // => undefined
at(['a', 'b', 'c'], 5); // => undefined
at(['a', 'b', 'c'], '1.2'); // => undefined
Related
- object-has - Checks if path is a direct property of object.
- object-set - Sets the value at path of object.
- object-unset - Removes the property at path of object.
- to-path - Converts string to a property path array.
Contributing
Pull requests and stars are highly welcome.
For bugs and feature requests, please create an issue.