Get a nested prop using dot-notation with a optional default value as fallback
Built with ❤︎ by Tiaan and contributors
$ npm install --save get-nested-prop
# OR
$ yarn add get-nested-prop
const getNestedProp = require('get-nested-prop')
const obj = {
foo: {
bar: {
baz: 5
}
}
}
console.log(getNestedProp(obj, 'foo.bar.baz')) // 5
console.log(getNestedProp(obj, 'foo.bar.baz.boo', 5)) // 5
Contributions are welcome. Please open up an issue or create PR if you would like to help out.
Note: If editing the README, please conform to the standard-readme specification.
Licensed under the MIT License.