Skip to content

Instantly share code, notes, and snippets.

@conanak99
Last active March 8, 2016 23:57
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 conanak99/149299f8ae3adc47c382 to your computer and use it in GitHub Desktop.
Save conanak99/149299f8ae3adc47c382 to your computer and use it in GitHub Desktop.
// Với array
var foo = ["one", "two", "three"];
// Cách cũ
var one = foo[0];
var two = foo[1];
var three = foo[2];
// Dùng destructuring
var [one, two, three] = foo;
// Với object
var obj = {firstName:'Hoang', lastName:'Pham'};
// Cách cũ
var firstName = obj.firstName;
var lastName = obj.lastName;
// Dùng destructuring
var {firstName, lastName} = obj;
// Nếu muốn lấy tên biến khác tên field của object
var {firstName : fn, lastName : ln} = obj; //fn: Hoang, ln: Pham
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment