主题
get
js
_.get(object, path, [defaultValue])获取 object 在 path 的值。如果解析的值是 undefined,则返回 defaultValue 代替它。
¥Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
新增于
¥Since
3.7.0
参数
¥Arguments
object(对象):的反面;¥
object(Object): The object to query.path(数组|字符串):要获取的属性的路径。¥
path(Array|string): The path of the property to get.[defaultValue](*):undefined解析值返回的值。¥
[defaultValue]()*: The value returned forundefinedresolved values.
返回
¥Returns
(*):返回解析后的值。
¥()*: Returns the resolved value.
示例
¥Example
js
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'