Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Array.prototype.entries: index–value pair iterator

entries returns an iterator of consecutive index and value pairs, including positions that are holes in a sparse array.

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

Syntax

array.entries()

array.entries() returns a new iterator. Each next() yields a two-element [index, value] array from index zero to the receiver’s current length. A sparse hole is read as undefined; the iterator does not skip it as many callback methods do.

The iterator is single-use and is itself iterable. It is not a snapshot: length or value changes before an index is visited can affect the result. The method is generic for array-like receivers, while a null or undefined receiver throws TypeError. The example materializes a sparse iterator and shows all three indexes.

Examples

const values = ["A", , "C"];
const rendered = [...values.entries()].map(([index, value]) => `${index}:${value}`);
console.log(rendered.join("|"));

Result

0:A|1:undefined|2:C

Sources