Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. Functions
  5. The arguments object
  6. length

arguments.length

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

Thearguments.length data property contains the number of arguments passed to the function.

Value

A non-negative integer.

Property attributes ofarguments.length
Writableyes
Enumerableno
Configurableyes

Description

Thearguments.length property provides the number of arguments actually passed to a function. This can be more or less than the defined parameter's count (seeFunction.prototype.length). For example, for the function below:

js
function func1(a, b, c) {  console.log(arguments.length);}

func1.length returns3, becausefunc1 declares three formal parameters. However,func1(1, 2, 3, 4, 5) logs5, becausefunc1 was called with five arguments. Similarly,func1(1) logs1, becausefunc1 was called with one argument.

Examples

Using arguments.length

In this example, we define a function that can add two or more numbers together.

js
function adder(base /*, num1, …, numN */) {  base = Number(base);  for (let i = 1; i < arguments.length; i++) {    base += Number(arguments[i]);  }  return base;}

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-arguments-exotic-objects

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp