//1.从数组中快速定义提取变量
let [a, b, c] = [1,2,3];
console.log(a) //1
console.log(b) //2
console.log(c) //3
//本质上这种匹配属于 模式匹配, 只要等号两边模式相同,左边的变量就会对应的赋值
let [fo, [ba], [bz]] = [4,[5], [6]];
console.log(fo) //4
console.log(ba) //5
console.log(bz)//6
let [,,third] = [7,8,9];
console.log(third) //9
let [x,,y] = [1,2,3];
console.log(x)//1
console.log(y)//3
let [head,...tail] = [1,2,3,4];
console.log(head) //1
console.log(tail) //[2, 3, 4]
let [x1,y1,...z1] = [1]
console.log(x1) //1
console.log(y1) //undefined
console.log(z1) //[]
//2.从对象解析,对象与数组解构的不同点,数组是按顺序的,变量取值取决于位置
//对象没有次序,变量必须与属性名相同
let {foo, bar} = {foo: 'apple', bar : 'banana'}
console.log(foo)//apple
console.log(bar)//banana
//通过在对象分解中使用rest运算符(…),可以将对象的所有其余键放在新的对象变量中。
let {a, b, ...args} = {a: 100, b: 200, c: 300, d: 400, e: 500}
console.log(a); // 100
console.log(b); // 200
console.log(args); //对象 {c:300, d:400, e:500}