Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Array.prototype.includes: testing whether a value is present

includes returns a Boolean indicating whether an array range contains a value under SameValueZero comparison.

Version: ECMAScript 2026 draft; example target: Node.js 24.22.2

Syntax

array.includes(searchElement[, fromIndex])

array.includes(searchElement[, fromIndex]) searches from fromIndex and returns true at the first SameValueZero match. Consequently NaN equals NaN, and +0 equals -0. The method returns only a Boolean, not an index.

fromIndex is truncated to an integer; a negative index counts from the end, an excessively negative one starts at zero, and Infinity yields false. Holes are read as undefined and can therefore match. The method is generic for array-like receivers and does not mutate them; null/undefined throws TypeError. The example covers NaN, a hole, and a restricted starting point.

Examples

const values = [NaN, , 0];
console.log(values.includes(NaN));
console.log(values.includes(undefined));
console.log(values.includes(0, -1));
console.log(values.includes(NaN, 1));

Result

true
true
true
false

Sources