← All snippets
Array Destructuring
Unpack array values into named variables in one line — swap values, skip items, and grab the rest.
patternsCode
const [first, second, ...rest] = [1, 2, 3, 4, 5]
// first=1, second=2, rest=[3,4,5]
// swap variables without a temp
[a, b] = [b, a]