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.




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.

Parimal Ghadiyali
Parimal Ghadiyali

A web geek, an industry experienced web developer & tutor/instructor residing in India 🇮🇳