How to Get the "length" of JavaScript Map Object?

Unlike JavaScript arrays, the Map object does not have a length property. It does, however, have a size accessor property, which gives you number of elements in a Map object.

For Example:

const map = new Map();

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

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

This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.