Posted By

housecor on 09/23/10


Tagged


Versions (?)

Umlimited arguments to function


 / Published in: JavaScript
 

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

  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  

You need to login to post a comment.