Map.prototype.size

The number of key/value pairs in a Map.

Since ES2015 (ES6) Spec ↗

Syntax

map.size

Returns

number — The count of entries currently in the map.

Examples

const m = new Map([["a", 1], ["b", 2]]);
console.log(m.size);
Output
2
const m = new Map();
m.set("x", 1);
m.delete("x");
console.log(m.size);
Output
0

Notes

- A read-only accessor property, unlike array `length` which is assignable. - `Set` has an equivalent `size` property.

Browser & runtime support

EnvironmentSince version
chrome 38
firefox 19
safari 8
edge 12
node 0.12

See also