How to Check the Size of a JavaScript Map ?
Last Updated :
01 Feb, 2024
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' );
let mapSize = myMap.size;
console.log(mapSize);
|
Share your thoughts in the comments
Please Login to comment...