注意:**1.左边读取的字段,右手边必须有
2.读取的是右边的一个层级**
var obj = {
name:"lisi",age:18,skill:"vue",
s:{
sex:"male"
}
}
/*
var name = obj.name
var age = obj.age
var skill = obj.skill
*/
var {name,s} = obj
console.log(name);
console.log(s.sex);
例子
var obj = [
{name:"zheng",age:18,skill:"vue"},
{name:"zhang",age:17,skill:"js"},
{name:"liu",age:20,skill:"html"}
]
/* arr = [{name:"xx",skill:"xxx"},{name:"xx",skill:"xxx"}] */
var arr = []
for(var i=0;i<obj.length;i++){
/* var name = obj[i].name;
var skill = obj[i].skill; */
var {name,skill} = obj[i]
arr.push({
/* name:name,skill:skill */
name,
skill
})
}
console.log(arr);