Hosting Solutions
mobile_logo Table of Contents
seal_frontseal_back

Arguments

The Arguments object returns an Object object containing all arguments passed to a function. It is useful for creating functions that can intake an undetermined amount of arguments to process.

Access the object indexes like we access array indexes. function myFunction() { return arguments[0]+" | "+arguments[1]+" | "+arguments[2]; } var result = myFunction(100, false, "hello"); alert(result); Use a for loop or similar loop statement to iterate over the entire list of arguments. function sum() { var result = 0; for( i = 0; i < arguments.length; i++ ){ result += arguments[i]; } return result; } alert( sum(10, 5, 2, 3, 10) );

Click here to watch a video about using the Arguments object: Video: JavaScript Arguments Object Tutorial

Properties

callee - returns a reference to the function that the arguments are processing in. length - returns a number representing how many arguments are in the list.

JavaScript

Objects

ArgumentsArrayAudioBooleanDataTransferDateDocumentElementFunctionGlobalHistoryHTMLElementMathNavigatorNumberObjectRegExpScreenStorageStringWindowXMLHttpRequest