Navigate back to the homepage

includes() Method in JavaScript

Parimal Ghadiyali
June 24th, 2019 · 1 min read

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

1array.includes(searchElement)

Example

1const array = ["Red", "Orange", "Yellow", "Olive", "Green"];
2
3if(array.includes("Red")){
4 console.log("Red was found in the array"); // true
5} else {
6 console.log("Red was not found in the array"); // false
7}

Note: The includes() method is case sensitive.

Hope you find this helpful.

More articles from MeshWorld

How to find the array index key of multi-dimensional array

Javascript array includes() is an inbuilt function determines whether the array contains the specified element or not returning boolean value.

January 20th, 2019 · 1 min read

How to Get Values from Multi-dimensional Arrays with array_column()

array_column() is an inbuilt PHP function which is used to get the values from a single column from the multi-dimensional array or an array of objects.

November 15th, 2018 · 1 min read
© 2017–2020 MeshWorld
Link to $https://twitter.com/meshworldindiaLink to $https://facebook.com/meshworldindiaLink to $https://instagram.com/meshworld.india/