get-prop-safe

1.0.0 • Public • Published

get-prop-safe

Safely get nested properties on an object if they exist

Install

$ npm install get-prop-safe

Use

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

Package Sidebar

Install

npm i get-prop-safe

Weekly Downloads

420

Version

1.0.0

License

MIT

Unpacked Size

2.42 kB

Total Files

5

Last publish

Collaborators

  • seebigs