Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Destructure an Array

Data Structures, Operators & Stringseasy

Course · Section 9: Data Structures, Modern Operators and Strings · Lecture 108: Destructuring Arrays

Implement `firstTwo(arr)` returning `{ first, second }` using array destructuring.

Sample tests

Input: firstTwo([1,2,3])
Output: {"first":1,"second":2}
Input: firstTwo([9,8])
Output: {"first":9,"second":8}

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Indexing manually misses the point of destructuring.
Visualize this concept: Destructuring →
Approach & explanation (try first)

Array destructuring binds the first two elements by position.

Loading...
⌘/Ctrl + Enter

Run your code to see results.