How to Use the Map.prototype.size Method in Javascript?

Estimated read time 1 min read

The Map.prototype.size method is a property of the Map object in JavaScript that returns the number of elements in the Map. You can use it as follows:

let map = new Map();
map.set("A", 1);
map.set("B", 2);
map.set("C", 3);

console.log(map.size); // 3

In the example above, we created a new Map object and added three elements to it using the set method. Finally, we used the size property to retrieve the number of elements in the map, which returns 3.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply