解構(gòu)賦值:
1- 左右兩邊必須一樣,左右映射
2- 右邊依序是個東西
3- 聲明和賦值不可分開(必須在一條語句完成)
4- 自由程度高展鸡,可以自定 粒度
- 變量賦值
let [a, b, c] = [1, 2, 3]
console.log(a, b, c)
- json 賦值
基礎:
let {x,y,z}={x:1,y:2,z:3};
console.log(x,y,z);
復雜點:
let [json, arr, num, str] = [{ a: 1, b: 2 }, [1, 2, 3], 8, 'str']
console.log(json, arr, num, str)
*注意錯誤形式:
let [x,y,z]={x:1,y:2,z:3}; 數(shù)組 對應 json 不合法
let {x,y,z}={1,2,3}; 右邊不是 正確的 json