Friday, June 12, 2026
HomeLanguagesJavascriptLodash _.includes() Method

Lodash _.includes() Method

The _.includes() method is used to find the value is in the collection or not. If the collection is a string, it will be tested for a value sub-string, otherwise SameValueZero() method is used for equality comparisons. If the index is given and is negative, the value is tested from the end indexes of the collection as the offset.

Syntax:

_.includes( collection, value, index )

Parameters: This method accepts three parameters as mentioned above and described below:

  • collection: This parameter holds the collection to inspect. Collection can be an array or object or string.
  • value: This parameter holds the value to search for.
  • index: This parameter holds the index to search from.

Return Value: This method returns true if the value is found in the collection, else false.

Example 1:

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
  
// Collection of string
var name = [ 'gfg', 'neveropen', 'computer', 'science', 'portal' ];
  
// Check value is found or not by _.includes() method
console.log(_.includes(name, 'computer'));
  
// Check value is found or not by _.includes() method
console.log(_.includes(name, 'geeeks')); 
  
// Check value is found or not by _.includes() method
console.log(_.includes(name, 'gfg', 2));


Output:

true
false
false

Example 2:  

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
  
// Collection of integer value
var name = [ 10, 15, 20, 25, 30 ]; 
  
// Check value is found or not by _.includes() method
console.log(_.includes(name, 25));
  
// Check value is found or not by _.includes() method
console.log(_.includes(name, 35));
  
// Check value is found or not by _.includes() method
console.log(_.includes(name, 25, 3));


Output:

true
false
true
RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS