JavaScript: Array destructuring
1 min read

JavaScript: Array destructuring

I was comfortable with array destructuring but was unaware that the elements could be skipped. For example,

let nums = [1, 2, 3, 4, 5];
let [one, , three, , five] = nums;
console.log([one, three, five]); // prints [1,3,5]

Skipping the elements by leaving them out using an extra comma is known as sparse array destructuring.