Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of Es6 Array Destructuring Assignment
/* ES5 */
var cats = [ 'Maru', 'Colonel Meow', 'Grumpy Cat' ];
var yayCat = cats[0], lolCat = cats[2];
var tmpCat = yayCat;
yayCat = lolCat;
lolCat = tmpCat;
/* >= ES6 */
var cats = [ 'Maru', 'Colonel Meow', 'Grumpy Cat' ];
var [ yayCat, , lolCat ] = cats;
[ yayCat, lolCat] = [ lolCat, yayCat];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment