Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,23 @@ Above-and-beyond pathing syntax for nested-Array properties:

## Usage

<pre>
var _ = require('lodash-getpath'); // import lodash with the mixin provided
```js
const _ = require('lodash-getpath'); // import lodash with the mixin provided

// simple object example
var obj1 = { a: [1, 2, 3] };
const obj1 = { a: [1, 2, 3] };
_.getPath(obj1, 'a[0]') === 1; // positive index
_.getPath(obj1, 'a[0, 2]') === [1, 3]; // positive indexes
_.getPath(obj1, 'a[1, 1]') === [2, 2]; // repeated indexes (ok!)
_.getPath(obj1, 'a[-1]') === 3; // negative index
_.getPath(obj1, 'a[-1, -2]') === [3, 2]; // negative indexes

// a little more complex object
var pathUsersNames = 'users[].name';
const pathUsersNames = 'users[].name';
_.getPath({ users: [{ name: 'Steve' },{ name: 'Sam' }] }, pathUsersNames) === ['Steve', 'Sam']; // all indexes, with sub-key

// *any* complex object/array structure you can think of, pull out the data you need in a single query!
...
</pre>
```

Also available in the browser as simply `_getPath()` in the global context/window

Expand Down