神刀安全网

prop-deep: a Node module that returns a deeply-nested property if it exists

propDeep

prop-deep: a Node module that returns a deeply-nested property if it exists

Returns the given deeply-nested property of an object using dot-notation or an array of keys.

A curried function is produced if only one argument is passed.

Examples

Non-curried invocation:

var propDeep = require('prop-deep');  var object = {   a: {     b: {       c: 4     }   } };  propDeep('a.b.c', object); // => 4  propDeep(['a', 'b', 'c'], object); // => 4  propDeep('a.b.c.d', object); // => undefined  propDeep('a.b', object); // => { c: 4 } 

Curried invocation:

var propDeep = require('prop-deep');  var object = {   a: {     b: {       c: 4     }   } };  propDeep('a.b.c')(object); // => 4  propDeep(['a', 'b', 'c'])(object); // => 4  propDeep('a.b.c.d')(object); // => undefined  propDeep('a.b')(object); // => { c: 4 }  

Changelog

v1.0.0: First release

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » prop-deep: a Node module that returns a deeply-nested property if it exists

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮