ES6扩展运算符的使用

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <div></div>
        <div></div>
        <div></div>
    </head>
    <body>
        <script type="text/javascript">
            console.log(...[1, 2, 3])
            // 1 2 3
            console.log(1, ...[2, 3, 4], 5)
            // 1 2 3 4 5
            console.log([...document.querySelectorAll('div')]) //三个div
            var args = [1,2,3,4]
            console.log(...args) //1 2 3 4
            
            var arr = [{name:'bob',sex:''},{name:'boob',sex:''},{name:'obob',sex:''}]
            console.log(...arr) //出来的是单个obj
        </script>
    </body>
</html>

 

posted @ 2018-01-16 10:17  蓝色帅-橙子哥  阅读(201)  评论(0编辑  收藏  举报