JS Built-ins
Mapsizebeginner

Map size β€” two entries

πŸ“– Usage Example
const m = new Map([['a', 1], ['b', 2]])
console.log(m.size)   // β†’ 2
m.set('c', 3)
console.log(m.size)   // β†’ 3

Read Map.size to get the number of key-value pairs in the map.

Map.prototype.size

After adding two different keys, size equals 2.

Challenge: Verify that new Map([['a',1],['b',2]]).size equals 2.

πŸ’‘ Hints (1)
  • β€’ Setting the same key twice keeps size at 1