Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Array.prototype.values: value iterator

values returns a live iterator that reads successive indexed values, including undefined produced by holes.

Version: ECMAScript 2015 onward; example target: Node.js 24.22.2

Syntax

array.values()

array.values() creates a value iterator without copying elements. Every next() reads the current index and checks length again, so receiver changes made before a position is visited can be observed. A step result has value and done; once exhausted, the iterator stays exhausted.

Holes are not skipped: an ordinary read of a missing index produces undefined. The iterator is itself iterable, and Array.prototype[Symbol.iterator] initially refers to the same function as values. The method does not mutate and is generic for array-like values.

Creation requires a receiver other than null or undefined, otherwise it throws TypeError. Length conversion, indexed getters, and proxy traps occur during iteration, so their failures emerge from next(). The API was standardized in ECMAScript 2015.

Examples

const sparse = ["build", , "deploy"];
const iterator = sparse.values();
for (let step = iterator.next(); !step.done; step = iterator.next()) {
  console.log(String(step.value), step.done);
}
console.log(iterator.next().done);

const tasks = ["test"];
const live = tasks.values();
console.log(live.next().value);
tasks.push("release");
console.log(live.next().value, live.next().done);

Result

build false
undefined false
deploy false
true
test
release true

Sources