27.4 C
Gujarat
HomeJavascriptHow To Find map length in JavaScript

How To Find map length in JavaScript

what is a map?

The map is a collection of elements where each element is stored as a Key, or value pair.

How To get map length

In Javascript, we can easily get the length of a map using the size property. The map size property is read only and returns an integer value.

For Example:

const map = new Map();

map.set('foo', 1);
map.set('bar', 2);
map.set('baz', 3);

Now Get the map length using the size property

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

The size property is read-only and can’t be changed. Let’s take one more example

const map = new Map();

map.set('foo', 1);
map.set('bar', 2);

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

map.size = 7;

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

Here we tried to change the map size but we were unable to.

Adminhttps://rocoderes.com
Rocoderes is a blog you can learn HTML, CSS, JavaScript, React Js and Python along with creative coding stuff and free source code files.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

15,000FansLike
5,000FollowersFollow
535FollowersFollow
- Advertisment -spot_img

Subscribe to our newsletter

To be updated with all the latest news, offers and special announcements.

Most Popular