JS Built-ins
← Map50 / 55
Mapentriesintermediate

Map entries() β€” destructuring

πŸ“– 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()

You can destructure each [key, value] pair with for-of.

Challenge: Verify that destructuring entries works correctly.

πŸ’‘ Hints (1)
  • β€’ Map is iterable by default and yields the same as entries()