Export (0) Print
Expand All

length Property (arguments) 

Returns the actual number of arguments passed to a function by the caller.


[function.]arguments.length

function

Optional. The name of the currently executing Function object.

The length property of the arguments object is initialized by the scripting engine to the actual number of arguments passed to a Function object when execution begins in that function.

The following example illustrates the use of the length property of the arguments object.

function argTest(a, b) : String {
   var i : int;
   var s : String = "The argTest function expected ";
   var numargs : int = arguments.length; // Get number of arguments passed.
   var expargs : int = argTest.length;   // Get number of arguments expected.
   if (expargs < 2)
      s += expargs + " argument. ";
   else
      s += expargs + " arguments. ";
   if (numargs < 2)
      s += numargs + " was passed.";
   else
      s += numargs + " were passed.";
   s += "\n"
   for (i =0 ; i < numargs; i++){        // Get argument contents.
      s += "  Arg " + i + " = " + arguments[i] + "\n";
   }
   return(s);                            // Return list of arguments.
}

print(argTest(42));
print(argTest(new Date(1999,8,7),"Sam",Math.PI));

After compiling with the /fast- option, the output of this program is:

The argTest function expected 2 arguments. 1 was passed.
  Arg 0 = 42

The argTest function expected 2 arguments. 3 were passed.
  Arg 0 = Tue Sep 7 00:00:00 PDT 1999
  Arg 1 = Sam
  Arg 2 = 3.141592653589793

Community Additions

ADD
Show:
© 2015 Microsoft