Destructuring is a convenient way of extracting multiple values from data stored in objects and Arrays. ES6 introduced some significant improvements to the language, including the de-structuring of Objects and Arrays. Honestly speaking, these are my favorite edition in the JavaScript standard syntax.

Array destructuring

Let us take a look if we want to extract data from an array in es5.

Image for post

Here, we are doing something quite boring stuff and repeated the same thing again and again. But ES6 destructuring assignment makes it easier.

Image for post

We can also do this with the same result,

we can also declare variables before Assignment,

Image for post

Assign variables a default value:

Image for post

#destructuring #array-destructuring #javascript-destructuring #es6-destructuring #es6

Array Destructuring in JavaScript
1.85 GEEK