Skip to content

.includes() ​

In ES7, the Array object introduced the includes() function which checks if certain value is included in an array. This replaces the old method of checking for inclusivity with indexOf(el) !== -1.

js
const array1 = [1, 2, 3];
console.log(array1.includes(2));
// true

// Old Way
console.log(array1.indexOf(2) !== -1)
// true