一、数组的解构赋值

1-1:demo1
let a = [1,2,3];
let [a1,a2,a3] = a;
console.log(a1);
console.log(a2);
console.log(a3);

1-2:demo2
let a = [1,2,3];
let [b1, ...b] = a;
console.log(b1);
console.log(b);

二、防止解构失败,给变量默认值

let [e,f = 100] = [2];
console.log(e);
console.log(f);

三、对象的解构赋值

let {foo,bar} = {foo:"foo",bar:"bar"};
console.log(foo);
console.log(bar);



重新指定变量名称
let {color:sky} = {color:'blue'};
console.log(sky);

四、复杂对象的解构赋值

五:字符串的解构赋值

网友评论