Array.prototype.includes()
Array.prototype.includes() is a JavaScript method in the Array category. Determines whether an array includes a certain value. The syntax is array.includes(searchElement, fromIndex). It returns A boolean. A typical example: [1, 2, 3].includes(2) // true. Another practical use — Check if value exists: const fruits = ['apple', 'banana', 'orange'] console.log(fruits.includes('banana')) // true console.log(fruits.includes('grape')) // false Its time complexity is O(n), which matters when it runs over large inputs. The TypeScript signature is (searchElement: T, fromIndex?: number): boolean. Common pitfall — Uses SameValueZero comparison. includes() uses SameValueZero equality, which handles NaN correctly: [NaN].includes(NaN) → true, unlike indexOf(). A close sibling is Array.prototype.map(), which creates a new array populated with the results of calling a provided function on every element. A close sibling is Array.prototype.filter(), which creates a new array with all elements that pass the test implemented by the provided function. A close sibling is Array.prototype.reduce(), which executes a reducer function on each element, resulting in a single output value.