Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Map.prototype.size

The number of entries in a Map.

Available since: ES2015

Syntax

map.size

Return value

numberThe number of entries.

Examples

The size of a collection:

const map = new Map([['x', 1], ['y', 2]]);
 
console.log(map.size);

Output:

2

Notes

It is a property, not a method, and it is called size, not length as in arrays.

See also

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.

Thanks for reading!

Donate to the site — we work hard for you.