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, c] is an array destructuring expression.
On the left-hand side of the array destructuring statement, we need to place the variables to which we want to assign the array values, using a syntax similar to an array literal. On the right-hand side, we need to place an array (actually any iterable object) whose values we want to extract.
The previous example code can be made even shorter in this way:
let [a, b, c] = [1, 2, 3];
Here, we create the variables on the same statement, and instead of providing the array variable, we provide the array with a construction literal.
If there are fewer variables than items in the array, then only the first items are considered.
If you place a non-iterable object on the right-hand side of the array destructuring assignment syntax, then a TypeError exception is thrown.