MeshWorld India Logo MeshWorld.
others 1 min read

includes() Method in JavaScript

Parimal Ghadiyali
By Parimal Ghadiyali
includes() Method in JavaScript

ES2016 Specifications included the includes() method for Array data structure.

The includes() method check if an array includes a certain element, returning true or false as appropriate.

Syntax

array.includes(searchElement);

Example

const array = ["Red", "Orange", "Yellow", "Olive", "Green"];

if (array.includes("Red")) {
  console.log("Red was found in the array"); // true
} else {
  console.log("Red was not found in the array"); // false
}

Note: The includes() method is case sensitive.

Hope you find this helpful.