美文网首页
js展开运算符

js展开运算符

作者: 空白_0ec8 | 来源:发表于2019-05-04 15:14 被阅读0次

    将多个值保存到一个变量中,用在函数和数组中

    在函数中使用

    let f = (...b) => {

        b.forEach((num) => console.log(num))

      }

      f(1, 2, 3, 4, 5)

    // 1 2 3 4 5

    在数值中使用

    将arr1插入arr2

    const arr1 = [1, 2]

    const arr2 = [...arr1, 3]

    console.log(arr2)

    // [1, 2, 3]

    push()

    const arr1 = [1, 2]

    const arr2 = ['a', 'b', 'c']

    arr1.push(...arr2)

    console.log(arr1)

    // [1, 2, "a", "b", "c"]

    ps: 小白一枚,最近在学js做个笔记加深印象

    相关文章

      网友评论

          本文标题:js展开运算符

          本文链接:https://www.haomeiwen.com/subject/wpbxoqtx.html