1.解构赋值有:
数组解构赋值实例:
//数组的解构赋值
const arr=[1,2,3,4];
let [a,b,c,d]=arr;
//更复杂的匹配规则
const arr=['a','b',['c','d',['e','f','g']]];
const [ ,b]=arr;//"b"
const [ , , g]=['e','f','g']; //"g"
const [ , ,[ , ,g]]=['c','d',['e','f','g']]; //"g"
const [ , ,[ , ,[ , ,g]]]=arr; //"g"
//扩展运算符
const arr1=[1,2,3];
const arr2=["a","b"];
const arr3=["cdx",23];
const arr4=[...arr1,...arr2,...arr3];//合并:[1,2,3,"a","b","cdx",23]
//默认值
const arr5=[1,undefined,undefined];
const [a,b,c,d]=arr;//arr中的d的值直接赋值为undefined
const arr6=[1,null,undefined];
const [a,b=2,c,d]=arr;//arr中的b的值为null
//交换变量
let a=20;
let b=10;
[a,b]=[b,a];
//接受多个 函数返回值
function f1(id){
....
return [true, {name:'小明',gender:"女",id:id} ,'请求成功'];
};
const [status,data,msg]=f1(123);//结果: