Skip to main content

includes() JavaScript Array Method – How to Check If an Array Includes an Item

Whenever you use includes() on an array, the method does the following:

  1. It checks if the calling array includes the method's first argument.
  2. It returns true if the array includes the argument. Otherwise, it returns false.
note

A calling array is an array on which you used includes(). So, in bestColorsList.includes("white"), bestColorsList is the calling array.

Syntax of the includes() Method

includes() accepts two arguments. Here is the syntax:

callingArray.includes(valueToFind, startIndex);

Argument 1: valueToFind

A valueToFind is the first argument accepted by the includes() method. It defines the value you wish to find in the calling array.

Example 1: Check if a given array includes "Tuesday"

["Sunday", "Tuesday", "Friday"].includes("Tuesday");

// The invocation above will return: true

Try it on StackBlitz

Note that the includes() method is case-sensitive.

Example 2: Check if a given array includes "SunDay"

["Sunday", "Tuesday", "Friday"].includes("SunDay");

// The invocation above will return: false

Try it on StackBlitz

Example 3: Check if a given array includes 5

[1, 3, 5, 7].includes(5);

// The invocation above will return: true

Try it on StackBlitz

Argument 2: startIndex

The startIndex argument is optional. It specifies the index position where you want the computer to start searching for the valueToFind argument.

note

The startIndex argument's default value is 0. Therefore, if omitted, the search will begin at index 0.

Example 1: From the 3rd index position, check if a given array includes "Tuesday"

const daysOfWeek = [
"Sunday",
"Tuesday",
"Thursday",
"Friday",
"Tuesday",
"Sunday",
"Tuesday",
"Friday",
];

daysOfWeek.includes("Tuesday", 3);

// The invocation above will return: true

Try it on StackBlitz

Example 2: From the 1st index position, check if a given array includes "Sunday"

const daysOfWeek = [
"Sunday",
"Tuesday",
"Friday",
"Monday",
"Tuesday",
"Friday",
];

daysOfWeek.includes("Sunday", 1);

// The invocation above will return: false

Try it on StackBlitz

tip
  • To find the index position of an item within an array, use indexOf().
  • You can also use includes() on a string. Learn more here.

Overview

includes() checks if its calling array includes the method's first argument.

Tweet this article