-
-
Save conanak99/149299f8ae3adc47c382 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
// 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