Skip to content

Instantly share code, notes, and snippets.

@jjsub
Last active July 21, 2016 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjsub/b72018b6b41700d87ce0708a91b06ec1 to your computer and use it in GitHub Desktop.
Save jjsub/b72018b6b41700d87ce0708a91b06ec1 to your computer and use it in GitHub Desktop.
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