//数组解构
let arr = [1,2,3,4,5,6,7]
let [one,two] = arr
let [one, , ,four] = arr
console.log(one,two,four)

let arr = 'abcd'
let [first, ,third] = arr
console.log(first,third)

let [first, ,third] = new Set([1,2,5,6,7])
console.log(first,third)

let user = { name:'s',surname:'t'};
[user.name,user.surname] = [1,2]
console.log(user)

//循环解构
let user = { name:'s',surname:'t'};
for( let [k,v] of Object.entries(user)){
   console.log(k ,v)
}

//剩余变量解构
let arr = [1,2,3,4,5,6,7,8,9]
let [first,second,...last] = arr
console.log(first,second,last)

//当数据为空时,解构赋值为undefined
let arr = []
let [first,second,...last] = arr
//可以设置默认值
let [first='a',second,...last] = arr
console.log(first,second,last)