ScanSkill

includes

The includes() method checks if the item exists in the array or not.

Syntax

array.includes(item)

The includes() method attaches to the right side of an array variable using the . operator. It takes in a parameter and checks if the given parameter exists in the array or not. It returns a boolean value.

Example

const randomArray = [1,2,3,4,5,'hello'];

console.log(randomArray.includes('hello')); // Prints: true

console.log(randomArray.includes(5000)); // Prints: false

The includes() checks if the item exists, if it does then it returns true, else it returns false.