Destructuring Example 12

Destructuring arrays - pick only what you need

by shravan

JavaScript

let numbers = [1, 2, 3, 4, 5];

let [a, b] = numbers;

console.log(a, b); //1 2

let [x, y, , , z] = numbers;

console.log(x, y, z); //1 2 5

let [i, , j, , k] = numbers;

console.log(i, j, k); //1 3 5