The Wayback Machine - https://web.archive.org/web/20240611105104/https://www.geeksforgeeks.org/javascript-array-includes-method/
Open In App

JavaScript Array includes() Method

Last Updated : 04 Jun, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The includes() method returns true if an array contains a specified value. Conversely, it returns false if the value is not found. This method simplifies checking for the presence of an element within an array, providing a straightforward boolean result.

Syntax

array.includes(searchElement, start);

Parameters

  • searchElement: This parameter holds the element that will be searched.
  • start: This parameter is optional and it holds the starting point of the array, where to begin the search the default value is 0.

Return Value

It returns a Boolean value i.e., either True or False.

Example 1: Searching for number in an array

Here, the method will search for element 2 in that array.

javascript
// Taking input as an array A
// having some elements.
let A = [1, 2, 3, 4, 5];

// includes() method is called to
// test whether the searching element
// is present in given array or not.
a = A.includes(2)

// Printing result of includes().
console.log(a);

Output
true

Example 2: Searching for a string in an array

Here, the method will search for the element ‘cat’ in that array and returns false as ‘cat’ is not present in the array.

javascript
// Taking input as an array A
// having some elements.
let name = ['gfg', 'cse', 'geeks', 'portal'];

// includes() method is called to
// test whether the searching element
// is present in given array or not.
a = name.includes('cat')

// Printing result of includes()
console.log(a);

Output
false

We have a complete list of Javascript Array methods, to check those please go through this Javascript Array Complete referencearticle.

Supported Browsers:


Previous Article
Next Article

Similar Reads

String includes() Method in JavaScript
JavaScript str.includes() function is used to check if the argument string is present in the given string or not. This function is case-sensitive. The syntax of this function is as follows: str.includes(searchString, position) Arguments The first argument to this function searchString is the string to be searched in the given string. The second arg
2 min read
JavaScript typedArray.includes() Method
The typedArray.includes() is an inbuilt function in JavaScript which is used to check whether a particular element is included by the given typedArray or not and accordingly it returns true and false. Syntax: typedarray.includes(Element, Index); Parameters: It accepts two parameter which are specified below- Element: It is the element which are bei
2 min read
What is includes() Method in JavaScript ?
In JavaScript, the includes() method is used to determine whether a string contains another string or a specified value. It returns true if the string contains the specified value, and false otherwise. Syntax:string.includes(searchValue, startIndex)string: The string in which to search for the specified value.searchValue: The value to search for wi
1 min read
JavaScript String includes() Method
The includes() method returns true if a string contains a specified string. Otherwise, it returns false. The includes() method is case-sensitive and can accept an optional start position parameter, simplifying substring searches within strings for various applications. Note: The includes() method is case sensitive i.e. it will treat the Uppercase C
2 min read
JavaScript TypedArray.prototype.includes() Method
In JavaScript the TypedArray.prototype.includes() method is used to check that the given typed array contains a specific given element or not, if it contains the element it returns true otherwise false. SyntaxtypedArray.includes(searchElement)ORtypedArray.includes(searchElement, fromIndex)ParameterssearchElement: The value to search for. fromIndex:
1 min read
How to check whether an array includes a particular value or not in JavaScript ?
In this article, we will discuss the construction of an array followed by checking whether any particular value which is required by the user is included (or present) in the array or not. But let us first see how we could create an array in JavaScript using the following syntax- Syntax: The following syntax would be helpful for any user for the cre
3 min read
How do I check if an Array includes a value in JavaScript?
We are going to learn how to check if a value is present in an array or not. We will need the array we want to search through and the target element we are looking for. JavaScript arrays serve as convenient containers for holding lists of elements, accessible through a single variable. Once we have a target element we can perform various search alg
4 min read
How to check if an array includes an object in JavaScript ?
In JavaScript, an array acts like like list. It's a way to group multiple items together under one name. You can store different things in your list, like numbers, words, or even other lists. Each item in the list has its own place, and you can access it using a number called its "index." We will check if an array includes an object or not in JavaS
4 min read
TypeScript Array includes() Method
TypeScript includes() method allows you to determine if a specific element is present, within an array. can also determine if a particular element exists or not at a particular index position. Syntax:array.includes(searchElement[, fromIndex])Parameters:searchElement: The value to search for within the array.fromIndex (optional): The starting index
2 min read
Node.js Buffer.includes() Method
Buffer is a temporary memory storage which stores the data when it is being moved from one place to another. It is like an array of integers. The Buffer.includes() method checks whether the provided value is present or included in the buffer or not. Syntax: buffer.includes( value, byteOffset, encoding ); Parameters: This method accept three paramet
2 min read