Horje
How to Check the Size of a JavaScript Map ?

To check the size (number of key-value pairs) of a Map in JavaScript, you can use the size property. The size property is a property of the Map object that returns the number of elements in the Map.

Example: Here, mapSize will be equal to 3 because there are three key-value pairs in the Map.

Javascript

let myMap = new Map();
 
myMap.set('key1', 'value1');
myMap.set('key2', 'value2');
myMap.set('key3', 'value3');
 
// Check the size of the Map
let mapSize = myMap.size;
 
console.log(mapSize); // Output: 3

Output

3



Reffered: https://www.geeksforgeeks.org


JavaScript

Related
What is the use of the Map.prototype.keys method in JavaScript Maps ? What is the use of the Map.prototype.keys method in JavaScript Maps ?
What is the use of the Map.prototype.clear method in JavaScript Maps ? What is the use of the Map.prototype.clear method in JavaScript Maps ?
What is the use of the Get method in Maps in JavaScript ? What is the use of the Get method in Maps in JavaScript ?
Difference Between a Set and an Array Difference Between a Set and an Array
What is the use of the Add method in Sets in JavaScript ? What is the use of the Add method in Sets in JavaScript ?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
13