| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat | [Back] [Original] |
Get to know MDN better
Dieser Inhalt wurde automatisch aus dem Englischen bersetzt, und kann Fehler enthalten. Erfahre mehr ber dieses Experiment.
Diese Funktion ist gut etabliert und funktioniert auf vielen Gerten und in vielen Browserversionen. Sie ist seit April 2021 browserbergreifend verfgbar.
Das Intl.ListFormat-Objekt ermglicht eine sprachsensitive Listenformatierung.
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"
Intl.ListFormat()Erstellt ein neues Intl.ListFormat-Objekt.
Intl.ListFormat.supportedLocalesOf()Gibt ein Array zurck, das diejenigen der bereitgestellten Locales enthlt, die untersttzt werden, ohne dass auf die Standard-Locale des Laufzeitsystems zurckgegriffen werden muss.
Diese Eigenschaften sind auf Intl.ListFormat.prototype definiert und werden von allen Intl.ListFormat Instanzen gemeinsam genutzt.
Intl.ListFormat.prototype.constructorDie Konstruktorfunktion, die das Instanzobjekt erstellt hat. Fr Intl.ListFormat-Instanzen ist der Anfangswert der Intl.ListFormat-Konstruktor.
Intl.ListFormat.prototype[Symbol.toStringTag]Der Anfangswert der [Symbol.toStringTag]-Eigenschaft ist der String "Intl.ListFormat". Diese Eigenschaft wird in Object.prototype.toString() verwendet.
Intl.ListFormat.prototype.format()Gibt einen sprachspezifisch formatierten String zurck, der die Elemente der Liste darstellt.
Intl.ListFormat.prototype.formatToParts()Gibt ein Array von Objekten zurck, die die verschiedenen Komponenten reprsentieren, die verwendet werden knnen, um eine Liste von Werten in einer localesensiblen Art zu formatieren.
Intl.ListFormat.prototype.resolvedOptions()Gibt ein neues Objekt mit Eigenschaften zurck, die die Locale- und Stilformatierungsoptionen widerspiegeln, die whrend der Konstruktion des aktuellen Intl.ListFormat-Objekts berechnet wurden.
Das folgende Beispiel zeigt, wie man einen List-Formatter mit der englischen Sprache erstellt.
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
Das folgende Beispiel zeigt, wie man einen List-Formatter erstellt, der formatierte Teile zurckgibt.
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" } ];
| Spezifikation |
|---|
| ECMAScript 2027 Internationalization API Specification # listformat-objects |
Intl.ListFormatObject/FunctionIntlIntl.CollatorIntl.DateTimeFormatIntl.DisplayNamesIntl.DurationFormatIntl.LocaleIntl.NumberFormatIntl.PluralRulesIntl.RelativeTimeFormatIntl.SegmenterDer Bauplan fr ein besseres Internet.
Teile dieses Inhalts sind 19982026 von einzelnen mozilla.org-Mitwirkenden. Inhalte sind verfgbar unter einer Creative-Commons-Lizenz.
| Web Proxy Viewer | New URL | Original Page |