JavaScript Array includes() method

The includes() method in JavaScript is used to check if an array includes a specified element. This method returns a Boolean value indicating whether the specified element is found in the array.

Here is an example of how the includes() method works:

const array1 = [1, 2, 3, 4, 5];

const result = array1.includes(3);

// the result will be: true

In the code example above, we first declare an array called array1 that contains the numbers 1 through 5. We then use the includes() method to check if the array1 array includes the number 3. The includes() method takes a single argument, which is the element to search for in the array. In this case, we search for the number 3.

As a result of calling the includes() method, the result variable will be set to true, because the array1 array does indeed include the number 3. If the element we were searching for was not found in the array, the result variable would be set to false.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: