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