Funktion: 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.

Die length Daten-Eigenschaft einer Function-Instanz gibt die Anzahl der erwarteten Parameter der Funktion an.

Probieren Sie es aus

function func1() {}

function func2(a, b) {}

console.log(func1.length);
// Expected output: 0

console.log(func2.length);
// Expected output: 2

Wert

Eine Zahl.

Eigenschaften von Funktion: length
Schreibbarnein
Aufzählbarnein
Konfigurierbarja

Beschreibung

Die length-Eigenschaft eines Function-Objekts zeigt an, wie viele Argumente die Funktion erwartet, d.h. die Anzahl der formalen Parameter:

Im Gegensatz dazu ist arguments.length lokal in einer Funktion und gibt die Anzahl der tatsächlich an die Funktion übergebenen Argumente an.

Der Function-Konstruktor ist selbst ein Function-Objekt. Seine length-Dateneigenschaft hat den Wert 1.

Aus historischen Gründen ist Function.prototype selbst aufrufbar. Die length-Eigenschaft von Function.prototype hat den Wert 0.

Beispiele

Verwendung von function length

js
console.log(Function.length); // 1

console.log((() => {}).length); // 0
console.log(((a) => {}).length); // 1
console.log(((a, b) => {}).length); // 2 etc.

console.log(((...args) => {}).length);
// 0, rest parameter is not counted

console.log(((a, b = 1, c) => {}).length);
// 1, only parameters before the first one with
// a default value are counted

console.log((({ a, b }, [c, d]) => {}).length);
// 2, destructuring patterns each count as
// a single parameter

Spezifikationen

Specification
ECMAScript® 2025 Language Specification
# sec-function-instances-length

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
length
Configurable: true

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Siehe auch