CKTIS / JavaScript
Map.prototype.size: entry count
The size property reads the current number of key–value entries in a Map as a non-negative integer.
Version: ECMAScript 2015 onward; example target: Node.js 24.22.2
Syntax
map.sizemap.size invokes an accessor inherited from Map.prototype and returns the number of non-deleted entries. It counts every key regardless of its value, including an entry storing undefined. Updating an existing key does not change the count; a new set adds one, a successful delete subtracts one, and clear makes it 0.
size is an accessor property, not a method: do not call map.size(). Its prototype descriptor is non-enumerable and has no setter. Therefore Reflect.set(map, "size", n) returns false unless an own property arrangement overrides it; ordinary assignment to the inherited setter-less accessor throws TypeError in strict code.
The getter requires a receiver with Map internal data; calling it with an object, Set, or unhandled Proxy throws TypeError. The property has been standard since ECMAScript 2015. The specification defines the result, not a particular lookup complexity, so portable code should not rely on an implementation detail.
Examples
const map = new Map([["a", undefined], ["b", 2]]);
console.log(map.size);
map.set("a", 3);
console.log(map.size);
map.delete("b");
console.log(map.size);
const descriptor = Object.getOwnPropertyDescriptor(Map.prototype, "size");
console.log(typeof descriptor.get, descriptor.set === undefined, descriptor.enumerable);
console.log(Reflect.set(map, "size", 99), map.size);
try { descriptor.get.call({}); } catch (error) { console.log(error instanceof TypeError); }Result
2 2 1 function true false false 1 true