.size
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.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.