In this tutorial, you’ll learn about the JavaScript Array includes method. This method is used to check if an array contains or includes a particular value. Let’s have a look at an example:
let arr = [1,2,3,4,5];
if(arr.includes(3)) {
console.log('item found')
} else {
console.log('item not found')
}
includes method also accepts an optional parameter to specify the index from which to search. By default, the index to search parameter is zero.
let arr = [1,2,3,4,5];
if(arr.includes(3,2)) {
console.log('item found')
} else {
console.log('item not found')
}