Access Function Arguments with the arguments Array in JavaScript

Description

The following code shows how to access Function Arguments with the arguments Array.

Example


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function displayArguments()<!--from   w  w  w.j ava 2  s. c  o  m-->
{
document.write("The following arguments were passed:<BR>");
for(i=0; i<arguments.length; i++)
{
document.write(i," = ",arguments[i],"<BR>");
}
}
displayArguments(3,"AAA",-7,"BBB");
</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Access Function Arguments with the arguments Array in JavaScript