MeshWorld India LogoMeshWorld.
others1 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.

Share_This Twitter / X
Parimal Ghadiyali
Written By

Parimal Ghadiyali

A web geek, industry-experienced web developer & instructor residing in India ๐Ÿ‡ฎ๐Ÿ‡ณ. Passionate about learning new things and making things on the Internet.

Enjoyed this article?

Support MeshWorld and help us create more technical content