JS Built-ins
ObjectObject.fromEntriesbeginner

Object.fromEntries() β€” reverse of Object.entries

πŸ“– 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() β€” round-trip with Object.entries

Object.fromEntries(Object.entries(obj)) creates a shallow clone of obj. This demonstrates the inverse relationship.

Challenge: Implement roundTrip(obj) that does Object.fromEntries(Object.entries(obj)).

roundTrip({ a: 1, b: 2 }) // β†’ { a: 1, b: 2 }
πŸ’‘ Hints (1)
  • β€’ `Object.fromEntries(Object.entries(obj))` is a common shallow-clone pattern.