Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/damianc/obj-path

Getting object property by a path string.
https://github.com/damianc/obj-path

javascript object-path object-property

Last synced: about 1 month ago
JSON representation

Getting object property by a path string.

Awesome Lists containing this project

README

        

# `ObjPath`

Getting object property by a path string.

## Installation

```
npm i @damianc/obj-path
```

## Use

```
const obj = {
foo: {
bar: [10, 20, 30, 40]
}
}

ObjPath(obj, 'foo.bar[1]')
// 20
```

```
const obj = {
foo: {
bar: [
120,
{ baz: [{
quux: 200
}] }
]
}
};

ObjPath(obj, 'foo.bar[1].baz[0].quux')
// 200
```

```
const obj = {
foo: [1, 2, [3, 4]]
};

ObjPath(obj, 'foo[2][0]')
// 3
```