Intl.ListFormat

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.

Das Intl.ListFormat-Objekt ermöglicht sprachsensitive Listenformatierung.

Probieren Sie es aus

const vehicles = ["Motorcycle", "Bus", "Car"];

const formatter = new Intl.ListFormat("en", {
  style: "long",
  type: "conjunction",
});
console.log(formatter.format(vehicles));
// Expected output: "Motorcycle, Bus, and Car"

const formatter2 = new Intl.ListFormat("de", {
  style: "short",
  type: "disjunction",
});
console.log(formatter2.format(vehicles));
// Expected output: "Motorcycle, Bus oder Car"

const formatter3 = new Intl.ListFormat("en", { style: "narrow", type: "unit" });
console.log(formatter3.format(vehicles));
// Expected output: "Motorcycle Bus Car"

Konstruktor

Intl.ListFormat()

Erstellt ein neues Intl.ListFormat-Objekt.

Statische Methoden

Intl.ListFormat.supportedLocalesOf()

Gibt ein Array zurück, das die angegebenen Locales enthält, die unterstützt werden, ohne auf die Standard-Locale der Laufzeitumgebung zurückgreifen zu müssen.

Instanz-Eigenschaften

Diese Eigenschaften sind auf Intl.ListFormat.prototype definiert und werden von allen Intl.ListFormat-Instanzen geteilt.

Intl.ListFormat.prototype.constructor

Die Konstruktorfunktion, die das Instanzobjekt erstellt hat. Für Intl.ListFormat-Instanzen ist der anfängliche Wert der Intl.ListFormat-Konstruktor.

Intl.ListFormat.prototype[Symbol.toStringTag]

Der anfängliche Wert der [Symbol.toStringTag]-Eigenschaft ist der String "Intl.ListFormat". Diese Eigenschaft wird in Object.prototype.toString() verwendet.

Instanz-Methoden

Intl.ListFormat.prototype.format()

Gibt einen sprachspezifisch formatierten String zurück, der die Elemente der Liste darstellt.

Intl.ListFormat.prototype.formatToParts()

Gibt ein Array von Objekten zurück, welches die verschiedenen Komponenten repräsentiert, die verwendet werden können, um eine Liste von Werten lokalisiert zu formatieren.

Intl.ListFormat.prototype.resolvedOptions()

Gibt ein neues Objekt mit Eigenschaften zurück, die die Locale- und Stilformatierungsoptionen widerspiegeln, die während der Konstruktion des aktuellen Intl.ListFormat-Objekts berechnet wurden.

Beispiele

Verwendung von format

Das folgende Beispiel zeigt, wie ein List-Formatter mit der englischen Sprache erstellt wird.

js
const list = ["Motorcycle", "Bus", "Car"];

console.log(
  new Intl.ListFormat("en-GB", { style: "long", type: "conjunction" }).format(
    list,
  ),
);
// Motorcycle, Bus and Car

console.log(
  new Intl.ListFormat("en-GB", { style: "short", type: "disjunction" }).format(
    list,
  ),
);
// Motorcycle, Bus or Car

console.log(
  new Intl.ListFormat("en-GB", { style: "narrow", type: "unit" }).format(list),
);
// Motorcycle Bus Car

Verwendung von formatToParts

Das folgende Beispiel zeigt, wie ein List-Formatter erstellt wird, der formatierte Teile zurückgibt.

js
const list = ["Motorcycle", "Bus", "Car"];
console.log(
  new Intl.ListFormat("en-GB", {
    style: "long",
    type: "conjunction",
  }).formatToParts(list),
);

// [ { "type": "element", "value": "Motorcycle" },
//   { "type": "literal", "value": ", " },
//   { "type": "element", "value": "Bus" },
//   { "type": "literal", "value": ", and " },
//   { "type": "element", "value": "Car" } ];

Spezifikationen

Specification
ECMAScript® 2025 Internationalization API Specification
# listformat-objects

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
ListFormat
ListFormat() constructor
format
formatToParts
resolvedOptions
supportedLocalesOf

Legend

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

Full support
Full support
Partial support
Partial support
See implementation notes.
Has more compatibility info.

Siehe auch