JavaScript Map size Tutorial

In this section, we will learn what the Map size property is and how to use it in JavaScript.

JavaScript Map size Property

The `size` property returns the number of elements in the target map object.

Notes:

  • Each pair of keys and values is considered as one element in a map.
  • The return value of this property is of type integer.

The size property is read-only.

JavaScript Map size property Syntax:

map.size;

Example: using Map size property in JavaScript

const map = new Map();
 map.set("John","222-22222222");
 map.set(22 , 2000);
 map.set(true, false); 
 map.set("Jack", "333-3234232");

 console.log(`The size of the map is: ${map.size}`);

Output:

The size of the map is: 4

Facebook
Twitter
Pinterest
LinkedIn

Top Technologies