JS Built-ins
ObjectObject.fromEntriesbeginner

Object.fromEntries() β€” Map to object

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

Use Object.fromEntries() to convert an iterable of [key, value] pairs into a plain object.

Object.fromEntries() with a Map

Since Map is iterable and yields [key, value] pairs, you can pass a Map directly to Object.fromEntries.

Challenge: Implement mapToObject(map) that converts a Map<string, unknown> to a plain object.

mapToObject(new Map([['a', 1], ['b', 2]])) // β†’ { a: 1, b: 2 }
πŸ’‘ Hints (1)
  • β€’ `Map` is iterable and yields `[key, value]` pairs β€” exactly what `Object.fromEntries` expects.