https://github.com/seebigs/get-prop-safe
Safely get nested properties on an object if they exist
https://github.com/seebigs/get-prop-safe
Last synced: about 1 month ago
JSON representation
Safely get nested properties on an object if they exist
- Host: GitHub
- URL: https://github.com/seebigs/get-prop-safe
- Owner: seebigs
- Created: 2018-03-21T22:57:03.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-21T23:28:49.000Z (about 8 years ago)
- Last Synced: 2025-06-07T05:35:55.165Z (about 1 year ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# get-prop-safe
Safely get nested properties on an object if they exist
## Install
```
$ npm install get-prop-safe
```
## Use
```js
var getPropSafe = require('get-prop-safe');
var obj = {
one: {
two: {
three: 3,
},
four: [
{
five: 5,
},
{
six: [6, 7, 8],
},
],
},
};
getPropSafe(obj, 'one.two.three'); // 3
getPropSafe(obj, 'one.four[1].six[0]'); // 6
getPropSafe(obj, 'one.not.found'); // undefined
getPropSafe(undefined, 'one.two.three'); // undefined
```