Umlimited arguments to function


/ Published in: JavaScript
Save to your folder(s)

Pass as many arguments as you wish. You can access them in the arguments array.


Copy this code and paste it in your HTML
  1. function addStuff() {
  2. var total = 0;
  3. for (var ii = 0; ii < arguments.length; ii++) {
  4. //Not only does this iterate through arguments, it uses the + to force addition instead of concatenation
  5. total += +arguments[ii];
  6. }
  7. return total;
  8. }

Report this snippet


Comments


You need to login to view comments.