ES6-解析赋值

1.注意事项

  • A.左右两边结构必须一样
  • B.右边必须是个东西
  • C.声明和赋值不能分开(必须在一句话里完成)

2.代码如下

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>解构赋值</title>
    <script>
        let [a0, b0, c] = [12, 5, 8];
        let {d,e,f} = {d: 12,e: 21,f: 23};
        console.log(a0, b0, c);
        // 结果12,5,8
        console.log(d, e, f);
        // 结果12,21,23
        let [{a,b},[n1, n2, n3], num1, str1] = [{a: 1,b: 2},[12, 5, 8], 8, 'cxzcv'];
        let [json,arr, num2, str2] = [{a: 1, b: 2},[12, 5, 8], 7, 'cx']
        console.log(a, b, n1, n2, n3, num1, str1);
        console.log(json, arr, num2, str2);
    </script>
</head>
<body>
</body>
</html>
posted @ 2020-05-21 23:15  东血  阅读(338)  评论(0编辑  收藏  举报

载入天数...载入时分秒...