has.js 757 B

123456789101112131415161718192021222324252627282930313233343536
  1. var baseHas = require('./_baseHas'),
  2. hasPath = require('./_hasPath');
  3. /**
  4. * Checks if `path` is a direct property of `object`.
  5. *
  6. * @static
  7. * @since 0.1.0
  8. * @memberOf _
  9. * @category Object
  10. * @param {Object} object The object to query.
  11. * @param {Array|string} path The path to check.
  12. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  13. * @example
  14. *
  15. * var object = { 'a': { 'b': 2 } };
  16. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  17. *
  18. * _.has(object, 'a');
  19. * // => true
  20. *
  21. * _.has(object, 'a.b');
  22. * // => true
  23. *
  24. * _.has(object, ['a', 'b']);
  25. * // => true
  26. *
  27. * _.has(other, 'a');
  28. * // => false
  29. */
  30. function has(object, path) {
  31. return object != null && hasPath(object, path, baseHas);
  32. }
  33. module.exports = has;