数组的解构赋值

 //概念
 var [a, b, c] = [1, 2, 3];//a 1,b 2,c 3

 let [foo, [[bar], baz]] = [1, [[2], 3]];//foo 1,bar 2,baz 3

 let [head, ...tail] = [1, 2, 3, 4]; //head  1 tail // [2, 3, 4]

 let [, , third] = ["foo", "bar", "baz"]; //third  "baz"


 let [x, y, ...z] = ['a']; //x  "a",y  undefined,z  []

//使用解构赋值实现两个变量的交换
let a=1,b=2;
[a,b]=[b,a]

posted @ 2021-08-17 16:29  yongerbingxuan  阅读(32)  评论(0)    收藏  举报