Intl.ListFormat.prototype.resolvedOptions()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2021年4月.
Intl.ListFormat.prototype.resolvedOptions() メソッドは、現在の Intl.ListFormat オブジェクトの構築時に計算されたロケールとスタイル整形オプションを反映したプロパティを持つ新しいオブジェクトを返します。
試してみましょう
const deListFormatter1 = new Intl.ListFormat("de-DE", { type: "disjunction" });
const options1 = deListFormatter1.resolvedOptions();
console.log(options1.locale);
// Expected output (Firefox / Safari): "de-DE"
// Expected output (Chrome): "de"
console.log(options1.style);
// Expected output: "long"
console.log(options1.type);
// Expected output: "disjunction"
構文
js
listFormat.resolvedOptions();
返値
指定された Intl.ListFormat オブジェクトの構築時に計算されたロケールと整形オプションを反映したプロパティを持つオブジェクトです。
解説
resolvedOptions() から返されるオブジェクトには、以下のプロパティがあります。
locale-
実際に使用したロケールの BCP 47 言語タグ。このロケールにつながる入力 BCP 47 言語タグに Unicode 拡張値が要求された場合、要求されたキーと値のペアのうち、このロケールで対応しているものが
localeに含まれます。 style-
コンストラクターの
options引数の中でこのプロパティに指定された値、または既定値 ("long") がです。この値は、"long"、"short"、"narrow" のいずれかです。 type-
コンストラクターの
options引数の中でこのプロパティに指定された値、または既定値 ("conjunction") がです。この値は、"conjunction"、"disjunction"、"unit" のいずれかです。
例
>resolvedOptions の使用
js
const deListFormatter = new Intl.ListFormat("de-DE", { style: "short" });
const usedOptions = de.resolvedOptions();
console.log(usedOptions.locale); // "de-DE"
console.log(usedOptions.style); // "short"
console.log(usedOptions.type); // "conjunction" (the default value)
仕様書
| Specification |
|---|
| ECMAScript® 2026 Internationalization API Specification> # sec-Intl.ListFormat.prototype.resolvedoptions> |
ブラウザーの互換性
Loading…