Chapter VIII · Arrays

Array Destructuring

Array destructuring unpacks sequential array values directly into distinct local variables.

01 How It Works

Think of sliding items sequentially out of slots into separate containers.

Variables match sequential index positions in the source array structure.

example.js
const rgb = [255, 128, 0];
const [red, green, blue] = rgb;
  1. 1. Target a source array.

  2. 2. Wrap target variable names inside square brackets [].

  3. 3. Extract positional values.

02 Practical Example

Here is how you might see this concept applied in real-world code:

practical.js
const coords = [10.5, 20.1];
const [lat, lng] = coords;

Key Takeaway

Array destructuring provides concise syntax for unpacking ordered list items.

Related Concepts