arguments.length
property contains the number of arguments passed to the function.
The arguments.length property provides the number of arguments actually passed to a function. This can be more or less than the defined parameter's count (see
Function.length
).
arguments.length
In this example we define a function that can add two or more numbers together.
function adder(base /*, n2, ... */) {
base = Number(base);
for (var i = 1; i < arguments.length; i++) {
base += Number(arguments[i]);
}
return base;
}
Note the difference between
Function.length
and arguments.length
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'Arguments Exotic Objects' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
length
|
Chrome 1 | Edge 12 | Firefox 1 | IE 4 | Opera 4 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs Yes |
完整支持