get source npm

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

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

Arguments

  1. object (Object)

    The object to query.

  2. path (Array|string)

    The path of the property to get.

  3. [defaultValue] (*)

    The value returned if the resolved value is undefined.

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'