JS Built-ins
← Map38 / 55
Mapkeysbeginner

Map keys() β€” type of iterator

πŸ“– Usage Example
const m = new Map([['a', 1], ['b', 2]])
for (const k of m.keys()) {
  console.log(k) // 'a', 'b'
}

Use Map.keys() to iterate over all keys in insertion order.

Map.prototype.keys()

keys() returns a MapIterator.

Challenge: Verify the type of the keys() return value.

πŸ’‘ Hints (1)
  • β€’ keys() returns a MapIterator β€” an iterable iterator object