解构赋值

2018-12-21  本文已影响0人  asmuzi
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        let [a, b, c] = [12, 5, 8];

        console.log(a);
        console.log(b);
        console.log(c);
    </script>
</head>

<body>

</body>

</html>

tip:解构赋值两边的结构必须一致
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        // let [a, b, c] = [12, 5, 8];

        let { a, b, c } = { a: 12, b: 5, c: 8 };

        console.log(a);
        console.log(b);
        console.log(c);
    </script>
</head>

<body>

</body>

</html>
上一篇下一篇

猜你喜欢

热点阅读