Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Map.prototype.values: value iterator

The values method returns a live iterator over Map values in the insertion order of their corresponding keys.

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

Syntax

map.values()

map.values() creates a new Map iterator. Each successful next() returns the value of the next entry in key order. Object values remain the same references, and equal values under different keys are returned separately; the iterator does not deduplicate.

The iterator is lazy, not a snapshot. An entry deleted before its visit is skipped, updating a not-yet-visited entry yields the new value, and an entry added before the end can be visited. Updating an already visited key does not repeat it. After done: true, later additions do not resume the iterator.

The method takes no meaningful arguments and requires a receiver with Map internal data; an object, Set, or unhandled Proxy throws TypeError. It has been standard since ECMAScript 2015. When association with keys matters, use entries() rather than inferring parallel positions.

Examples

const shared = {};
const map = new Map([["a", shared], ["b", 2], ["c", 2]]);
const values = map.values();
console.log(values.next().value === shared);
map.set("b", 20);
map.delete("c");
map.set("d", 4);
console.log(values.next().value);
console.log(values.next().value);
console.log(values.next().done);
map.set("e", 5);
console.log(values.next().done);
console.log([...new Map([["x", 1], ["y", 1]]).values()].join(","));
try { Map.prototype.values.call({}); } catch (error) { console.log(error instanceof TypeError); }

Result

true
20
4
true
true
1,1
true

Sources