_.has

_.has(object, path)

source npm package

Checks if path is a direct property of object.

Since

0.1.0

Arguments

  1. object (Object): The object to query.
  2. path (Array|string): The path to check.

Returns

(boolean): Returns true if path exists, else false.

Example

var object = { 'a': { 'b': 2 } };
var other = _.create({ 'a': _.create({ 'b': 2 }) });
 
_.has(object, 'a');
// => true
 
_.has(object, 'a.b');
// => true
 
_.has(object, ['a', 'b']);
// => true
 
_.has(other, 'a');
// => false