CKTIS / JavaScript
Map.prototype.entries: key–value pair iterator
The entries method returns a live iterator of [key, value] pairs in Map insertion order and is the default Map iteration method.
Version: ECMAScript 2015 onward; example target: Node.js 24.22.2
Syntax
map.entries()map.entries() creates a new Map iterator object. Each successful next() returns a fresh two-element [key, value] array; mutating that array does not change the Map entry, although contained objects remain the same references. map[Symbol.iterator] is the same function as map.entries, so for...of and spread receive pairs by default.
The iterator is lazy, not a snapshot. It preserves insertion order, skips entries deleted before they are visited, and can observe entries added before it reaches the end; updating the value of a not-yet-visited key yields the new value. Once next() has returned done: true, later additions do not resume that iterator.
The method takes no meaningful arguments and requires a receiver with Map internal data; borrowing it for a plain object, Set, or unhandled Proxy throws TypeError. It has been standard since ECMAScript 2015. Use keys() or values() when only that component is needed, avoiding pair arrays.
Examples
const map = new Map([["a", 1], ["b", 2]]);
const entries = map.entries();
const first = entries.next().value;
console.log(JSON.stringify(first));
first[1] = 99;
console.log(map.get("a"));
map.delete("b");
map.set("c", 3);
const second = entries.next();
console.log(JSON.stringify(second.value), second.done);
console.log(entries.next().done);
map.set("d", 4);
console.log(entries.next().done);
console.log(map[Symbol.iterator] === map.entries);Result
["a",1] 1 ["c",3] false true true true