includes()
ES7+Determines whether an array includes a certain value among its entries.
Syntax
array.includes(searchElement, fromIndex)Parameters
searchElement any The value to search for
fromIndex number optionalPosition to start searching from
Return Value
boolean
true if the value is found, otherwise false
Examples
JavaScript
const fruits = ['apple', 'banana', 'cherry'];
console.log(fruits.includes('banana'));
console.log(fruits.includes('mango')); Output:
// true
false