JS Built-ins
← Map46 / 55
Mapentriesbeginner

Map entries() β€” spread to array

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

Use Map.entries() to iterate over [key, value] pairs in insertion order.

Map.prototype.entries()

entries() returns an iterator of [key, value] pairs.

Challenge: Verify that spreading entries() gives the correct array.

πŸ’‘ Hints (1)
  • β€’ Each entry is a [key, value] array pair