Search⌘ K
AI Features

Destructuring an Array

Explore how to destructure arrays in TypeScript to move data into variables, swap variable values, and collect remaining elements with the rest operator. Understand practical ways to work with arrays for cleaner and more efficient code.

Case 1: Moving data into a variable

Destructuring an array puts data into separated variables, swaps data, or collects the remaining items of an array.

The first case is moving data into a variable. The assignment starts by having on the left side of the equal sign ...