almai
3/13/2019 - 7:55 AM

ES2016 spread operatror

function add() {
  var values = Array.prototype.splice.call(arguments, [0]),
      total = 0;
      
  for (var value of values) {
    total += value
  }
  return total;
}

sum(1, 2, 3, 4); // => 10

//-------- The same with spread operator ----------//

function add(...values) {
  var total = 0;
      
  for (var value of values) {
    total += value
  }
  return total;
}







var list = [1, 2, 3];
var toAdd = [4, 5, 6];

list.push(...toAdd);

console.log(list);