_baseGet.js 672 B

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