1.变量值进行交换
let a=10,b=20; console.log(a,b); [a,b]=[b,a]; console.log(a,b);
2.数组解构
// 等号左边是右边的模板,必须一样 let [a,b,c] =[1,2,3]; console.log(a,b,c);
可预设默认值
[a,b,c='JS'] =[1,2]; console.log(a,b,c);
可使用归并参数
[a,b,...c] =[1,2,3,5,6,66]; console.log(a,b,...c);
可省略部分参数
[,,c] =[1,2,3,5,6,66]; console.log(c);
3.对象解构
({id,name}={id:10,name:"手机"}); console.log(id,name);
推荐:《2021年js面试题及答案(大汇总)》