.size

karel.de.smetoutlook.com's avatar
Published Dec 31, 2021Updated Jun 26, 2023
Contribute to Docs

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

Codebyte Example

The following example uses the size property to confirm the number of elements in a map after deleting a key-value pair.

Code
Output
Loading...

All contributors

Contribute to Docs

Learn JavaScript on Codecademy