_.result(object, path, [defaultValue])
This method is like _.get
except that if the resolved value is a function it's invoked with the this
binding of its parent object and its result is returned.
Since
0.1.0
Arguments
object
(Object): The object to query.path
(Array|string): The path of the property to resolve.[defaultValue]
(*): The value returned forundefined
resolved values.
Returns
(*): Returns the resolved value.
Example
var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };_.result(object, 'a[0].b.c1');// => 3_.result(object, 'a[0].b.c2');// => 4_.result(object, 'a[0].b.c3', 'default');// => 'default'_.result(object, 'a[0].b.c3', _.constant('default'));// => 'default'
当前内容版权归 lodash.com 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 lodash.com .