JavaScript Array .includes() Method

The JavaScript array.includes() method checks if an array contains a given value and returns either true or false.

Description

The includes() method checks if an element exists in an array and will return a boolean. As you may have guessed, it returns true if the array has the value and it returns false if the array does not contain the value.

1const insects = ["grasshopper", "ant", "hornet", "fly"];
2insects.includes("ant"); // true
3insects.includes("hornet"); // true
4insects.includes("beetle"); // false

Syntax

1array.includes(searchElement);
2array.includes(searchElement, fromIndex);

Parameters

searchElement

The value that you're checking for in the array.

fromIndex (optional)

The index in which to start searching for searchElement. If no value is provided, this method will search from the beginning of the array.

Return Value

This method will return true if the tested array includes the given value, otherwise it will return false.

More stuff I've written

Let's work together

Elevate your online presence with a user-focused website. Reach out for a discovery call & let's turn your ideas into a stunning digital experience.

An image of Traek Wells