ES6 Destructuring part 1
Array Destructuring in ES6
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.
ES6 has added a shorthand syntax for destructuring an array.
The following example demonstrates how to unpack the elements of an array into distinct variables:
We can use also destructure an array returned by a function.
For example:
Notice that we left the second argument's place empty.
The destructuring syntax also simplifies assignment and swapping values:
Tap Try it Yourself to play around with the code.
Comments
Post a Comment