CKTIS / JavaScript
Array.prototype.indexOf: index of the first strict match
indexOf returns the first index of an element equal under ===, or -1 when it is absent.
Version: ECMAScript 2026 draft; example target: Node.js 24.22.2
Syntax
array.indexOf(searchElement[, fromIndex])array.indexOf(searchElement[, fromIndex]) searches forward from fromIndex, uses strict === comparison, and returns the first matching index. No match yields -1. Unlike includes, NaN never matches NaN, while +0 and -0 are equal.
fromIndex is truncated to an integer; a negative value counts from the end, an excessively negative one starts at zero, and Infinity immediately yields -1. Holes are skipped, so they do not match undefined. The method is generic for array-like receivers and does not mutate them; null/undefined throws TypeError. The example covers a duplicate, NaN, a hole, and a starting index.
Examples
const values = [NaN, , "x", "x"];
console.log(values.indexOf("x"));
console.log(values.indexOf("x", 3));
console.log(values.indexOf(NaN));
console.log(values.indexOf(undefined));Result
2 3 -1 -1