Skip to content

Instantly share code, notes, and snippets.

@keokilee
Created March 27, 2015 23:52
Show Gist options
  • Save keokilee/61db699057d4485c5ed8 to your computer and use it in GitHub Desktop.
Save keokilee/61db699057d4485c5ed8 to your computer and use it in GitHub Desktop.
ES6 Destructuring
// Assign first and second to the first two values in the array.
var nums = [1, 2, 3];
var firstES5 = nums[0];
var secondES5 = nums[1];
var [firstES6, secondES6] = nums;
// Assign the foo and bar properties from the object.
var object = {foo: 1, bar: 2};
// ES5
var foo = object.foo;
var bar = object.bar;
// ES6: This pattern matches the variable name to the object property
var {foo, bar} = object;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment