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.
Intl.ListFormat
オブジェクトは、言語を考慮したリストの整形ができるようにします。
試してみましょう
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()
-
新しい
Intl.ListFormat
オブジェクトを作成します。
静的メソッド
Intl.ListFormat.supportedLocalesOf()
-
指定したロケールのうち、ランタイムの既定のロケールに代替されることなく対応しているものを含む配列を返します。
インスタンスメソッド
Intl.ListFormat.prototype.format()
-
リストの要素を表す、言語を考慮して書式化された文字列を返します。
Intl.ListFormat.prototype.formatToParts()
-
ロケールを考慮した方法で値のリストを書式化するために使用できる、さまざまな部分を表すオブジェクトの配列を返します。
Intl.ListFormat.prototype.resolvedOptions()
-
現在の
Intl.ListFormat
オブジェクトの構築時に計算されたロケールおよびスタイルの書式化オプションを反映したプロパティを持つ、新しいオブジェクトを返します。
例
format の使用
次の例は、英語を使用したリストフォーマッターの作成方法です。
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
formatToParts の使用
次の例では、整形済みの部分を返すリストフォーマッターを生成する方法を示します。
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" } ];
仕様書
Specification |
---|
ECMAScript® 2025 Internationalization API Specification # listformat-objects |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.