A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/lodash-_-includes-method/ below:

Lodash _.includes() Method - GeeksforGeeks

Lodash _.includes() Method

Last Updated : 03 Sep, 2024

Lodash _.includes() method is used to find whether 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:

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

Example 1: In this example, we are checking whether the given value is present in the given collection or not by the use of the _.includes() method.

JavaScript
// Requiring the lodash library  
const _ = require("lodash");

// Collection of string
let name = ['gfg', 'geeks',
    '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: In this example, we are checking whether the given value is present in the given collection or not by the use of the _.includes() method.

JavaScript
// Requiring the lodash library  
const _ = require("lodash");

// Collection of integer value
let 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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4