JS Built-ins
ObjectObject.fromEntriesintermediate

Object.fromEntries() β€” transform values

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

Combining Object.entries, .map, and Object.fromEntries is a powerful pattern to transform object values.

Challenge: Implement doubleValues(obj) that returns a new object with all numeric values doubled.

doubleValues({ a: 1, b: 3 }) // β†’ { a: 2, b: 6 }
πŸ’‘ Hints (1)
  • β€’ Chain: `Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, v * 2]))`.