JavaScript Map size Property
Last Updated : 04 Jul, 2024
Improve
Map is a collection of elements where each element is stored as a Key, value pair. The Map.size property returns the number of key, and value pairs stored in a map.
Syntax
mapName.size
Return Value
An integer representing the number of key, value pairs stored in a map.
The below examples illustrate the Map.size property.
Example 1:
let GFGmap = new Map();
// Adding key, value pairs to the map
GFGmap.set('1', 'Apple');
GFGmap.set('2', 'Banana');
GFGmap.set('3', 'Mango');
// Printing number of key, value
// pairs stored in the map
console.log(GFGmap.size);
Output:
3
Example 2:
let GFGmap = new Map();
// Adding key, value pairs to the map
GFGmap.set('a', 'Apple');
GFGmap.set('b', 'Ball');
GFGmap.set('c', 'Cat');
GFGmap.set('d', 'Dog');
// Printing number of key, value
// pairs stored in the map
console.log(GFGmap.size);
Output:
4
Supported Browsers
- Google Chrome 38.0
- Microsoft Edge 12.0
- Firefox 13.0
- Internet Explorer 11.0
- Opera 25.0
- Safari 8.0
We have a complete list of Javascript Map methods, to check those please go through this JavaScript Map Complete Reference article.