November 2019
Beginner
804 pages
20h 1m
English
Earlier in this chapter, we discovered object destructuring. Array destructuring is another useful ES2015 feature (also supported by TypeScript). It works in a similar way to object destructuring, but with arrays instead.
We have all written code like this at some point:
const values = ['A', 'B', 'C']; const first = values[0]; const second = values[1]; const third = values[2];
It works fine, but it is also verbose. With array destructuring, we can easily extract elements of an array into other variables/constants.
Here's another version of the previous example, this time using array destructuring:
const values = ['A', 'B', 'C']; const [first,second,third] = values;
The variables that we are destructuring the array elements ...
Read now
Unlock full access