.size

The .size property returns the number of entries inside of a Map object.

Syntax

map.size;

Since .size is a property of Map, no parentheses are needed.

Example

Assuming there is a map of fruits, the number of keys can be checked with the .size property:

const fruits = new Map([
['Apples', 5],
['Oranges', 8],
]);
console.log(fruits.size); // Output: 2

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn JavaScript on Codecademy