JavaScript Array includes() Method
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 a number in an array
Here, the method will search for element 2 in that array.
// 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.
// 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:
JavaScript Array includes() Method- FAQs
What is the array includes method in JavaScript?
The includes() method in JavaScript determines whether an array contains a certain element, returning true if it does and false if it does not
What happens if the value is not found in the array?
If the value is not found in the array, the includes() method returns false. It performs a strict equality check for the specified element and, if no match is found, the result is false.
Does the includes() method modify the original array?
No, the includes() method does not modify the original array. It only checks for the presence of the specified element and returns a boolean result.
Can the includes() method be used with multi-dimensional arrays?
The
includes()method can be used with arrays containing any type of elements, including objects, strings, numbers,undefined, andnull. However, for objects, the method checks for object reference equality, not content equality.
What are some common use cases for the includes() method?
Common use cases for the
includes()method include:
- Checking if an array contains a specific value.
- Validating user input against a list of allowed values.
- Ensuring that an array does not contain duplicate entries before adding a new element.

