March 15, 2000 - Variable-Length Argument List

Yehuda Shiran March 15, 2000
Variable-Length Argument List
Tips: March 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Suppose you want to create a function that accepts string arguments and prints them with a line break after each one. Since the number of arguments is not known, the only way to handle this situation is through the arguments array:

function printList() {
  for (var i = 0; i < printList.arguments.length; ++i) {
    document.write(printList.arguments[i] + "<BR>")
}

See more examples in Column 59, IE 5.5's New Operators.