mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 16:47:49 +00:00
Bump to v3.7.0.
This commit is contained in:
33
object/get.js
Normal file
33
object/get.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import baseGet from '../internal/baseGet';
|
||||
import toPath from '../internal/toPath';
|
||||
|
||||
/**
|
||||
* Gets the property value of `path` on `object`. If the resolved value is
|
||||
* `undefined` the `defaultValue` is used in its place.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Object
|
||||
* @param {Object} object The object to query.
|
||||
* @param {Array|string} path The path of the property to get.
|
||||
* @param {*} [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'
|
||||
*/
|
||||
function get(object, path, defaultValue) {
|
||||
var result = object == null ? undefined : baseGet(object, toPath(path), path + '');
|
||||
return result === undefined ? defaultValue : result;
|
||||
}
|
||||
|
||||
export default get;
|
||||
Reference in New Issue
Block a user