bradxr
8/4/2018 - 11:18 AM

Use the Rest Operator with Function Parameters

create functions that take a variable number of arguments which are stored in an array for access later inside of the function

function howMany(...args) {
  return "You have passed " + args.length + " arguments.";
}

console.log(howMany(0, 1, 2));  // you have passed 3 arguments
console.log(howMany("string", null, [1, 2, 3] { }));  // you have passed 4 arguments