Add an array of parameters using the rest

restParameter variable represents an array, all the array-specific methods can be used for this variable:

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]

 

Guess you like

Origin www.cnblogs.com/qdlhj/p/11122377.html