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

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i get-prop-safe

      Weekly Downloads

      418

      Version

      1.0.0

      License

      MIT

      Unpacked Size

      2.42 kB

      Total Files

      5

      Last publish

      Collaborators

      • seebigs