JavaScript – Get Size of Map

To get the size of a Map in JavaScript, access size property of this Map. size is a read only property of Map object and returns an integer value representing the number of key-value pairs in this Map.

Syntax

The syntax to access size property on the Map map is

map.size;
ADVERTISEMENT

Examples

In the following example, we take a Map with two items and find the size of this Map programmatically using size property.

index.html

The size of an empty map is zero.

index.html

Conclusion

In this JavaScript Tutorial, we learned how to get the size of a Map in JavaScript using size property, with examples.