一、数组的解构
var names = ["abc", "cba", "nba"];
//var iteml=names[o]
//var item2=names[1]
//var item3=names[2]
//对数组的解构:·[]
var [iteml, item2, item3] = names;
console.log(iteml, item2, item3);
//·解构后面的元素
var [, itemz] = names;
console.log(itemz);
//解构一个元素,后面的元系全放新的数组
var [itema, ...newNames] = names;
//·解构的默认值
var [itema, itemb, itemc, itemd = "aaa"] = names;
console.log(itemd);
二、对象的解构
var obj = { name: "zs", age: 18, height: 1.88 };
//对象的解构:
var { name, age, height } = obj;
console.log(name, age, height);
//解构命名添加默认值
var { address: newAddress = "广州市" } = obj;
console.Log(newAddress);