ES6中的rest参数以及扩展运算符

1.rest参数的使用(…args)
ES6中引入rest参数,用于获取函数的参数,用来代替arguments
在这里插入图片描述

 //arguments
    // function data1() {
    //   console.log(arguments)
    // }
    // data1(12, 5, 3)

    // //rest参数
    // function data2(...args) {
    //   console.log(args)
    // }
    // data2(1, 2, 3)


    // function data3(a, b, ...args) {
    //   console.log(a);
    //   console.log(b)
    //   console.log(args)
    // }
    // data3(7, 8, 1, 9, 1)

    const arr = ['nihao', 'wohao', 'dajiahao']
    function hao() {
      console.log(arguments)
    }
    hao(...arr)

2.扩展运算符
扩展运算符能将【数组】转换为逗号分割的【参数序列】
在这里插入图片描述

<script>


    // 扩展运算符的使用
    //1.拼接数组
    const arr1 = ['piaoliang', 'keai'];
    const arr2 = ['wenrou', 'dafang']
    const arr3 = [...arr1, ...arr2]
    console.log(arr3)
    console.log("****************分隔符*********************")
    //2.拷贝数组(浅拷贝)
    const sanzhihua = ['E', 'G', 'M']
    const sanzhihua1 = [...sanzhihua]
    console.log(sanzhihua1)


    //将伪数组转换为真正的数组

    const divs = document.querySelectorAll('div')
    console.log(divs)
    const divArr = [...divs]
    console.log(divArr)
  </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值