es6--扩展运算符回顾

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 查找数组中最大的值
        var arr = [1,2,3,4,5,6];
        console.log(Math.max(...arr));

        // 合并数组
        var arr1 = [1,2,3];
        var arr2 = ['a','b'];
        console.log([...arr1,...arr2]);

        // 合并对象
        var obj1 = { name:'小明', age:12 };
        // var obj2 = { name: '小红', age: 11 }; // 误区:定义同属性(key值),会覆盖
        var obj2 = { sex: '男', kg: '50kg' }
        var obj3 = {
            ...obj1,
            ...obj2
        }
        console.log(obj3);
    </script>
</body>
</html>

 

posted @ 2021-01-24 22:27  小白咚  阅读(89)  评论(0编辑  收藏  举报