数组解构
- 左边是右边的模板必须一样
let [a,b,c] = [1,2,3];
- 如果之多的话…
let [d,e,...f] = [1,2,3,4,5,6,7,8,9];
- 指定第2个
[,a,] = [1,2,3];
- 交换值
[b,a] = [a,b];
对象解构
- 左边是右边的模板必须一样
- 用括号抱住
({id,name} = {id:40,name:'nihao'})
参数解构
- 数组传参
let sum = ([a,b])=>a+b;
console.log(sum[1,2]);
- 对象传参
let getName = ({name,email})=>[name,eamil];
console.log(getName({name:'nihao',email:'a@a.com'}));