SOURCE

//基本的用法
let a = 1;
let [b, c, d] = [1, 2, 3];
let [e,...f] = [1,2,3,4,5,6];
console.log(f);

//解构不成功 赋值 underfined;
let [foo] = [];
console.log(foo);

console.log("***********");

let [x,y,z] = new Set([1,2,3]);
console.log(x);

//斐波那契数列
function* fibs(){
    var a = 0;
    var b = 1;
    while(true){
        yield a;
        [a, b] = [b, a + b];
    }
}

var [h,i,j,k,l,m] = fibs();
console.log(l);
console.log(m);

console.log("***********");

var { foo:baz } = {foo:123};
console.log(baz);
console.log(foo);


let foo1;
({foo:foo1} = {foo:1223});
console.log(foo1);

let {ttt = 123} = {ttt:456};
console.log(ttt);

const [o, p , q, r] = 'hello';
console.log(o);

let { toString: s } = 123;
console.log(s);


//函数参数的解构赋值
function add([a,b]){
    return a + b;
}
console.log(add([1,2]));

function move({x=0,y=0} = {}){
    return [x,y];
}
move({x:3,y:4});

//用途
//交换
let a1 = 1;
let a2 = 2;
[a1,a2] = [a2,a1];


//提取json
let jsonData = {
    a3: 1,
    b3: 2,
    c3: 3
}
let { a3, b3, c3} = jsonData;
console.log(a);


console.log("***********");
var map = new Map();
map.set("id", 123);
map.set("name", 'aaa');
for(let [key, value] of map){
    console.log(key);
    console.log(value);
}
console 命令行工具 X clear

                    
>
console