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.

We'd love to hear more about your role and the company you work for
Please help us by answering a few questions.

arguments.length プロパティは、関数に渡された引数の数が入ります。

解説

arguments.length プロパティは、実際に関数に渡された引数の数を提供します。これは、定義された仮引数の数以上にも以下にもなることがあります(Function.length を参照してください)。

arguments.length の使用

この例では、2 つ以上の数を加算する関数を定義しています。

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

メモ: Function.length と arguments.length の違いに注意してください。

仕様書

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

ブラウザーの互換性

関連情報