ECMA Script 6 array destructuring assignment

ECMA script 6 has allowed us to assign an array element directly to a variable just like how we did it in python. Here is an example,

let [a, b, c] = [2, 3, 5];

console.log(a + b + c);

The right hand side array’s elements will get assigned to the left hand side variables based on the order of both the array’s elements and the variables. The above outcome is 10!

Like this post? Kindly share!