JS Built-ins
ObjectObject.fromEntriesbeginner

Object.fromEntries() β€” array of pairs 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()

Object.fromEntries(iterable) transforms an iterable of [key, value] pairs into a plain object. It is the inverse of Object.entries.

Challenge: Implement pairsToObject(pairs) that converts an array of [key, value] pairs into an object.

pairsToObject([['a', 1], ['b', 2]]) // β†’ { a: 1, b: 2 }
πŸ’‘ Hints (2)
  • β€’ `Object.fromEntries` is the reverse of `Object.entries`.
  • β€’ Duplicate keys are allowed β€” the last one wins.