_.get

_.get(object, path, [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

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

Returns

(*): Returns the resolved value.

Example

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'
doc_Lodash
2016-11-27 16:37:23
Comments
Leave a Comment

Please login to continue.