Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Pairs to Object

Data Structures, Operators & Stringshard

Course · Section 9: Data Structures, Modern Operators and Strings · Lecture 111: The Spread Operator (...)

Implement `flattenPairs(pairs)` turning an array of `[key, value]` pairs into an object.

Sample tests

Input: flattenPairs([["a",1],["b",2]])
Output: {"a":1,"b":2}
Input: flattenPairs([])
Output: {}

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Reaching for a manual reduce when fromEntries does it directly.

Learning resources

  • MDN: Destructuring assignment
Approach & explanation (try first)

Object.fromEntries consumes the pairs and builds the corresponding object.

Loading...
⌘/Ctrl + Enter

Run your code to see results.