Array Destructuring
Destructuring assignment is a concise syntax for unpacking values from arrays (or properties from objects) into distinct variables. Array destructuring uses position — the first variable gets the first element, the second gets the second, and so on.
Basic Destructuring
Wrap the variable names in square brackets on the left side of an assignment. You can skip elements with commas and provide default values for missing elements.
Swapping Variables
Array destructuring enables a one-line variable swap without a temporary variable — a classic party trick that is also genuinely useful.
Rest in Destructuring
Use the rest syntax (...rest) as the last element on the left to collect all remaining array items into a new array.
Function Return Values
Functions can return arrays and callers can destructure the result, giving multiple return values a clean, named feel.