October 2018
Intermediate to advanced
590 pages
15h 5m
English
Array destructuring is similar to object destructuring. Instead of using curly brackets, array destructuring uses brackets to do the destructuring. Here is an example of array destructuring:
let [first, second] = ['Traveling', 'Swimming', 'Shopping'];console.log(first); // Travelingconsole.log(second); // Swimming
You can also skip variables and only pick the one that you need, like the following:
let [,,third, fourth] = ['Traveling', 'Swimming', 'Shopping'];console.log(third); // Shoppingconsole.log(fourth); // undefined
As you can see, we skip the first two variables and only require the third and the fourth. However, in our case, the fourth variable doesn't match any elements in the array and its value remains as ...
Read now
Unlock full access