destructure an array javasript code example
Example 1: destructuring arrays with rest operator
// Rest operator on Arrays;
// It's usually shown as ...rest
// but you can name this what you like
// Think of it as "get the ...rest of the array"
const [q, r, ...callThisAnythingYouWant] = [1, 2, 3, 4, 5, 6, 7, 8];
console.log(q, r); // 1 2
console.log(callThisAnythingYouWant); // [ 3, 4, 5, 6, 7, 8 ]
Example 2: mdn destructuring
let a, b;
[a, b] = [1, 2];
console.log(a); // 1
console.log(b); // 2