利用rest 参数进行数组添加

Posted qdlhj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了利用rest 参数进行数组添加相关的知识,希望对你有一定的参考价值。

rest参数中的变量代表一个数组,所有数组特有的方法都可以用于这个变量:

function push(array, ...items) 
    items.forEach(function(item) 
      array.push(item);
      console.log(item);
    );
  
  let  a = [];
  push(a, 1, 2, 3)
  console.log(a)  //输出 [1, 2, 3]

 

以上是关于利用rest 参数进行数组添加的主要内容,如果未能解决你的问题,请参考以下文章