Date

“Object” Methods

_.get(object, path, [defaultValue])

source npm package

Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.

引入版本

3.7.0

参数
object (Object) : The object to query.
path (Array|string) : The path of the property to get.
[defaultValue] (*) : The value returned for undefined resolved values.

返回值
(*) : Returns the resolved value.

示例
var object = { 'a': [{ 'b': { 'c'3 } }] };
 
_.get(object, 'a[0].b.c');
// => 3
 
_.get(object, ['a', '0', 'b', 'c']);
// => 3
 
_.get(object, 'a.b.c', 'default');
// => 'default'