main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
882 bytes
|
Line | |
---|
1 | import baseGet from './_baseGet.js';
|
---|
2 |
|
---|
3 | /**
|
---|
4 | * Gets the value at `path` of `object`. If the resolved value is
|
---|
5 | * `undefined`, the `defaultValue` is returned in its place.
|
---|
6 | *
|
---|
7 | * @static
|
---|
8 | * @memberOf _
|
---|
9 | * @since 3.7.0
|
---|
10 | * @category Object
|
---|
11 | * @param {Object} object The object to query.
|
---|
12 | * @param {Array|string} path The path of the property to get.
|
---|
13 | * @param {*} [defaultValue] The value returned for `undefined` resolved values.
|
---|
14 | * @returns {*} Returns the resolved value.
|
---|
15 | * @example
|
---|
16 | *
|
---|
17 | * var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
---|
18 | *
|
---|
19 | * _.get(object, 'a[0].b.c');
|
---|
20 | * // => 3
|
---|
21 | *
|
---|
22 | * _.get(object, ['a', '0', 'b', 'c']);
|
---|
23 | * // => 3
|
---|
24 | *
|
---|
25 | * _.get(object, 'a.b.c', 'default');
|
---|
26 | * // => 'default'
|
---|
27 | */
|
---|
28 | function get(object, path, defaultValue) {
|
---|
29 | var result = object == null ? undefined : baseGet(object, path);
|
---|
30 | return result === undefined ? defaultValue : result;
|
---|
31 | }
|
---|
32 |
|
---|
33 | export default get;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.