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

Hope you found this post useful. It was published . Please show your love and support by sharing this post.