Skip to content

Instantly share code, notes, and snippets.

@Archakov06
Created April 22, 2018 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Archakov06/c62f9e9f99f4b0ab7ee206cc7d1877e2 to your computer and use it in GitHub Desktop.
Save Archakov06/c62f9e9f99f4b0ab7ee206cc7d1877e2 to your computer and use it in GitHub Desktop.
import baseGet from './.internal/baseGet.js'
/**
* Gets the value at `path` of `object`. If the resolved value is
* `undefined`, the `defaultValue` is returned in its place.
*
* @since 3.7.0
* @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 for `undefined` resolved values.
* @returns {*} Returns the resolved value.
* @see has, hasIn, set, unset
* @example
*
* const 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) {
const result = object == null ? undefined : baseGet(object, path)
return result === undefined ? defaultValue : result
}
export default get
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment