February 2018
Intermediate to advanced
298 pages
8h 22m
English
An array destructuring assignment is used to extract the values of an iterable object and assign them to the variables. It's called an array destructuring assignment because the expression is similar to an array construction literal.
Programmers used to do it this way to assign the values of an array to the variables:
var myArray = [1, 2, 3];
var a = myArray[0];
var b = myArray[1];
var c = myArray[2];
Here, we are extracting the values of an array and assigning them to the a, b, c variables respectively.
With an array destructuring assignment we can do this in a one-line statement:
let myArray = [1, 2, 3]; let a, b, c; [a, b, c] = myArray; //array destructuring assignment syntax
As you can see, [a, b, ...
Read now
Unlock full access