Need private packages and team management tools?Check out npm Teams »

get-obj-deep-val

1.0.0 • Public • Published

获取一个对象不论多少层级的属性值,如有多个只取一个,不存在则返回undefined

案例:

const getObjDeepVal = require('get-obj-deep-val')
let x = { a: { b: { c: { d: 1 } } } };
Object.prototype.getObjVal = function(key) {
 return getObjDeepVal(this, key)
}
console.log(x.getObjVal('a')) // { b: { c: { d: 1 } } }
console.log(getObjDeepVal(x, 'a')) // { b: { c: { d: 1 } } } 
console.log(x.getObjVal('c')) // { d: 1 }
console.log(x.getObjVal('d')) // 1
console.log(x.getObjVal('g')) // undefined

Keywords

none

Install

npm i get-obj-deep-val

DownloadsWeekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

1.27 kB

Total Files

3

Last publish

Collaborators

  • avatar