Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Web
Expertise: Intermediate
Jul 16, 1999

Passing Arguments to a JavaScript Function

JavaScript functions have a special property called arguments, which contains an array of input parameters. Using the "length" property of an array, you can iterate through the array for each parameter. This enables you to develop functions that can change as their parameters do.

<SCRIPT Language="JavaScript">
function foo() {
  var argv = foo.arguments;
  var argc = argv.length;
  for (var i = 0; i < argc; i++) {
    alert("Argument " + i + " = " + argv[i]);
<BODY onload="foo('hello', 'world');">
William Wen
Thanks for your registration, follow us on our social networks to keep up-to-date