JS Built-ins
Variablesbeginner

Variables β€” destructuring assignment

Destructuring

Destructuring lets you unpack values from arrays or objects into named variables.

Challenge: Write destructureArray() that:

  1. Destructures [1, 2, 3, 4, 5] into a, b, and rest (remaining elements)
  2. Returns { a, b, rest }
πŸ’‘ Hints (2)
  • β€’ Use [a, b, ...rest] = array syntax
  • β€’ The ...rest collects all remaining elements into an array