一、对象结构赋值
1.
let a,b
({a,b}={a:2,b:3})
console.log(a,b) //2,3
2.
let num,total
({a:num,b:total}={a:2,b:3})
console.log(num,total) //2,3
3.结构用例
let obj={
name:"ll",
nameList:[
{name:"qq"}
]
}
let {name:person,nameList:[name:otherperson]}=obj
console.log(person,otherperson)//ll,qq
二、数组解构赋值
1.
let a,b,c
[a,b,c]=[1,2]
console.log(a,b,c) //1,2,undefined
2.
[a,b,c=6]=[1,2]
console.log(a,b,c) //1,2,6
[a,b,c=6]=[1,2,3]
console.log(a,b,c) //1,2,3 c=6是默认值,当没有给c赋值的时候的默认值;当赋值之后会覆盖掉默认值
3.数组分割
let a,other
[a,...other]=[1,2,3,4] //...解构赋值
console.log(a,other)//1 [2,3,4]
4.
let a,b
[a,,b]=[1,2,3]
console.log(a,b)//1,2 逗号占位符