上QQ阅读APP看书,第一时间看更新
Destructuring
We have a new way to assign values to objects and arrays. Let’s look at some examples:
var [a, b] = ["hello", "world"];
console.log(a); // "hello"
console.log(b); // "world"
var obj = { name: "Diego", lastName: "Arguelles" };
var { name, lastName } = obj;
console.log(name); // "Diego"
var foo = function() {
return ["175", "75"];
};
var [height, weight] = foo();
console.log(height); //175
console.log(weight); //75