Thursday, October 16, 2025
HomeLanguagesJavascriptLodash _.has() Method

Lodash _.has() Method

Lodash _.has() method is used to check whether the path is a direct property of the object or not. It returns true if the path exists, it returns false.

Syntax:

_.has(object, path);

Parameters:

  • object: This parameter holds the object to query.
  • path: This parameter holds the path to check. The path will be an array or string.

Return Value:

This method returns true if the path exists. else it will return false.

Example 1: In this example, we are checking whether ‘a’ is present in the object or not by the use of the _.has() method.

Javascript




// Requiring the lodash library 
const _ = require("lodash");
 
// Given object
let object = { 'a': { 'b': 2 } };
 
// Use of _.has method
console.log(_.has(object, 'a'));
console.log(_.has(object, ['a']));
console.log(_.has(object, ['b']));


Output:

true
true
false

Example 2:  In this example, we are checking present of the passed value in the object or not by the use of the _.has() method.

Javascript




// Requiring the lodash library 
const _ = require("lodash");
 
// Given object
let object = { 'a': { 'b': 2 } };
 
// Use of _.has method
console.log(_.has(object, 'a.b'));
console.log(_.has(object, ['a', 'b']));
console.log(_.has(object, ['a', 'b', 'c']));


Output:

true
true
false
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS