Map.prototype.size
The number of entries in a Map.
Available since: ES2015
Syntax
map.sizeReturn value
numberThe number of entries.
Examples
The size of a collection:
const map = new Map([['x', 1], ['y', 2]]);
console.log(map.size);Output:
2Notes
It is a property, not a method, and it is called size, not length as in arrays.
See also
- Set.prototype.size — The number of values in a Set.
- Array.prototype.length — The number of elements in an array.
In the tutorial
- Map and Set — The Map and Set collections in JavaScript: a dictionary with keys of any type and a set of unique values.