_baseGet.js 616 B

12345678910111213141516171819202122232425
  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;