Saturday, July 4, 2026
HomeLanguagesJavascriptJavaScript Map size Property

JavaScript Map size Property

Map is a collection of elements where each element is stored as a Key, value pair. Map.size property is used to return the number of Key, and value pairs stored in a map.

Syntax:

mapName.size

Return Value: An integer representing number of Key, value pair stored in a map.

The examples below illustrate the Map.size property:

Example 1:

Javascript




let GFGmap = new Map();
  
// Adding key, value pairs to the map
GFGmap.set('1', 'Apple');
GFGmapset('2', 'Banana');
GFGmap.set('3', 'Mango');
  
// Printing number of key, value
// pairs stored in the map
console.log(GFGmap.size);


Output:

3

Example 2:

Javascript




let GFGmap = new Map();
  
// Adding key, value pairs to the map
GFGmap.set('a', 'Apple');
GFGmapset('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.

RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6900 POSTS0 COMMENTS
Nicole Veronica
12015 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6967 POSTS0 COMMENTS