Last active
July 21, 2016 22:16
-
-
Save jjsub/b72018b6b41700d87ce0708a91b06ec1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We can extract these values by index in ES5: | |
var | |
one = myArray[0], | |
two = myArray[1], | |
three = myArray[2]; | |
// one = 'a', two = 'b', three = 'c' | |
ES6 destructuring permits a simpler and less error-prone alternative: | |
var [one, two, three] = myArray; | |
// one = 'a', two = 'b', three = 'c' | |
or use the spread operator (...) to extract remaining elements: | |
var [one, ...two] = myArray; | |
// one = 'a', two = ['b, 'c'] | |
from: https://www.sitepoint.com/preparing-ecmascript-6-destructuring-assignment/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment