JavaScript tutorial:
arguments property

 

Applies to: Function Object

The arguments property is used to get an array containing each argument passed to the currently executing function.

Syntax

function.arguments[ ]

The function argument is the name of the currently executing function.

Return

Returns an array containing each argument passed to the currently executing function.

Example

The arguments property allows a graceful way for functions to handle a variable number of arguments. The length property of the array contains the number of arguments passed to the function.

The following example illustrates the use of the arguments property:

function ArgTest()
{
var i, s, numargs = ArgTest.arguments.length;
s = numargs;
if (numargs < 2)
s += " argument was passed to ArgTest. It was ";
else
s += " arguments were passed to ArgTest. They were " ;
for (i = 0; i < numargs; i++)
{
s += ArgTest.arguments[i] + " ";
}
return(s);
}
document.write(ArgTest(2, "Hello", 3));

  To run the code above, paste it into JavaScript Editor, and click the Execute button

See also: function Statement, length Property (Array)