域名預訂/競價,好“米”不錯過
<pre>//數(shù)組對象
const people = [
{name:'Henry',age:20},
{name:'Bucky',age:25},
{name:'Emily',age:30},
];
// 需求,取第一個age
// es5
var age = people[0].age;
console.log(age)//20
// es6解構
const [age] = people;
/**
* 因為第一層解構的是數(shù)組,所以會返回第一條的整條數(shù)據(jù)
*/
console.log(age)//{ name: 'Henry', age: 20 }
/**
* 如果想拿第一條數(shù)據(jù)的age值就得再解構一次
*/
const [{age}] = people;
console.log(age)//20</pre>
文章來源:田珊珊個人博客
來源地址:http://www.tianshan277.com/682.html
申請創(chuàng)業(yè)報道,分享創(chuàng)業(yè)好點子。點擊此處,共同探討創(chuàng)業(yè)新機遇!