--- title: arguments.length slug: Web/JavaScript/Reference/Functions/arguments/length translation_of: Web/JavaScript/Reference/Functions/arguments/length ---
{{jsSidebar("Functions")}}

本次函数调用时传入函数的实参数量.

Syntax

arguments.length

描述

arguments.length表示的是实际上向函数传入了多少个参数,这个数字可以比形参数量大,也可以比形参数量小(形参数量的值可以通过Function.length获取到).

例子

例子: 使用arguments.length

这个例中,我们定义了一个可以相加任意个数字的函数.

function adder(base, /*, n2, ... */) {
  base = Number(base);
  for (var i = 0; i < arguments.length; i++) {
    base += Number(arguments[i]);
  }
  return base;
}

Specifications

Specification Status Comment
{{SpecName('ES1')}} {{Spec2('ES1')}} Initial definition. Implemented in JavaScript 1.1
{{SpecName('ES5.1', '#sec-10.6', 'Arguments Object')}} {{Spec2('ES5.1')}}  
{{SpecName('ES6', '#sec-arguments-exotic-objects', 'Arguments Exotic Objects')}} {{Spec2('ES6')}}  
{{SpecName('ESDraft', '#sec-arguments-exotic-objects', 'Arguments Exotic Objects')}} {{Spec2('ESDraft')}}  

浏览器支持

{{Compat("javascript.functions.arguments.length")}}

相关链接