safe-get-attr
v1.0.1
Published
Safe-get-attr can help us quickly get attributes and ensure program robustness.
Downloads
2
Maintainers
Readme
safe-get-attr
Safe-get-attr can help us quickly get attributes and ensure program robustness.
get
npm i safe-get-attr --save-dev
use
import safeGetAttr from 'safe-get-attr'
const Tom = {
name:'Tom',
child:{
name:'Dick',
child:{
name:'Jack',
child:{
name:'Jerry'
}
}
},
}
const name1 = safeGetAttr(Tom, 'child', 'child', 'child', 'name')
// Jerry
const name2 = safeGetAttr(Tom, 'child', 'child', 'child', 'child', 'name')
// undefined but there's no error