Destructuring assignment

개념

unpack values from arrays, or properties from objects, into distinct variables.

Example

array basic

const foo = ['one', 'two'];
const [red, yellow, green, blue] = foo;
console.log(red) // one
console.log(yellow) // two
console.log(green) // undefined

swapping

const arr = [1, 2, 3];
[arr[2], arr[1]] = [arr[1], arr[2]];
console.log(arr); // [1, 3, 2]

Reference

array_destructuring - MDN