or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-lodash--has

The lodash method `_.has` exported as a module for checking if a path is a direct property of an object.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/lodash.has@4.5.x

To install, run

npx @tessl/cli install tessl/npm-lodash--has@4.5.0

index.mddocs/

lodash.has

The lodash method _.has exported as a Node.js module. This package provides a standalone implementation of lodash's has method for checking if a path is a direct property of an object, supporting both string and array path notations for deep property access.

Package Information

  • Package Name: lodash.has
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install lodash.has

Core Imports

var has = require('lodash.has');

For ES modules (using default import with CommonJS interop):

import has from 'lodash.has';

Basic Usage

var has = require('lodash.has');

var object = { 'a': { 'b': 2 } };
var other = Object.create({ 'a': Object.create({ 'b': 2 }) });

// Check direct properties
has(object, 'a');
// => true

// Check nested properties with string path
has(object, 'a.b');
// => true

// Check nested properties with array path
has(object, ['a', 'b']);
// => true

// Inherited properties return false
has(other, 'a');
// => false

// Safe with null/undefined objects
has(null, 'a');
// => false

Capabilities

Property Existence Checking

Checks if a path is a direct property of an object. Supports both string paths (like 'a.b') and array paths (like ['a', 'b']) for deep property checking.

/**
 * Checks if `path` is a direct property of `object`.
 *
 * @static
 * @since 0.1.0
 * @category Object
 * @param {Object} object The object to query.
 * @param {Array|string} path The path to check.
 * @returns {boolean} Returns `true` if `path` exists, else `false`.
 * @example
 *
 * var object = { 'a': { 'b': 2 } };
 * var other = Object.create({ 'a': Object.create({ 'b': 2 }) });
 *
 * has(object, 'a');
 * // => true
 *
 * has(object, 'a.b');
 * // => true
 *
 * has(object, ['a', 'b']);
 * // => true
 *
 * has(other, 'a');
 * // => false
 */
function has(object, path);

Path Format Support

The has function supports multiple path formats:

String paths:

  • Simple property: 'name'
  • Nested properties: 'user.profile.name'
  • Array indices: 'users[0].name'
  • Mixed notation: 'data.items[1].value'

Array paths:

  • Simple property: ['name']
  • Nested properties: ['user', 'profile', 'name']
  • Array indices: ['users', 0, 'name']
  • Mixed types: ['data', 'items', 1, 'value']

Behavior Details

Direct Property Checking

The has method only checks for direct properties (own properties) of the object, not inherited properties from the prototype chain. This is different from the in operator which also checks inherited properties.

Null Safety

The function safely handles null and undefined objects by returning false instead of throwing an error.

Array-like Objects

For array-like objects (including actual arrays), the function can check both numeric indices and length properties:

var array = [1, 2, 3];

has(array, '0');     // => true
has(array, 0);       // => true
has(array, 'length'); // => true
has(array, '3');     // => false

Symbol Properties

The function can check for Symbol properties when used as keys:

var sym = Symbol('test');
var obj = { [sym]: 'value' };

has(obj, sym); // => true

Error Handling

The has function does not throw errors under normal usage. It returns false for:

  • null or undefined objects
  • Non-existent paths
  • Invalid path formats

Internal implementation may throw TypeError for invalid function arguments in the memoization helper, but this should not occur in normal usage of the has function.