JS Built-ins
ObjectObject.entriesintermediate

Object.entries() β€” convert object to Map

πŸ“– Usage Example
// Get [key, value] pairs of an object
const obj = { a: 1, b: 2 }
Object.entries(obj)   // β†’ [['a', 1], ['b', 2]]

Use Object.entries() to get an array of [key, value] pairs for iterating over an object's own enumerable properties.

Object.entries() β€” interop with Map

Since Object.entries returns [key, value] pairs, you can pass the result directly to the Map constructor.

Challenge: Implement toMap(obj) that converts a plain object to a Map using Object.entries.

toMap({ a: 1, b: 2 }) // β†’ Map { 'a' => 1, 'b' => 2 }
πŸ’‘ Hints (1)
  • β€’ `new Map(iterable)` accepts an iterable of `[key, value]` pairs β€” exactly what `Object.entries` returns.