JS Built-ins
← Map37 / 55
Mapkeysbeginner

Map keys() β€” insertion order

πŸ“– 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 are iterated in insertion order.

Challenge: Verify that keys come out in the order they were inserted.

πŸ’‘ Hints (1)
  • β€’ Map.keys() respects insertion order, unlike plain object keys