You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
616 B

4 years ago
  1. var castPath = require('./_castPath'),
  2. toKey = require('./_toKey');
  3. /**
  4. * The base implementation of `_.get` without support for default values.
  5. *
  6. * @private
  7. * @param {Object} object The object to query.
  8. * @param {Array|string} path The path of the property to get.
  9. * @returns {*} Returns the resolved value.
  10. */
  11. function baseGet(object, path) {
  12. path = castPath(path, object);
  13. var index = 0,
  14. length = path.length;
  15. while (object != null && index < length) {
  16. object = object[toKey(path[index++])];
  17. }
  18. return (index && index == length) ? object : undefined;
  19. }
  20. module.exports = baseGet;