Intl.ListFormat.prototype.resolvedOptions()

Intl.ListFormat.prototype.resolvedOptions() メソッドは、現在の Intl.ListFormat オブジェクトの構築時に計算されたロケールとスタイル整形オプションを反映したプロパティを持つ新しいオブジェクトを返します。

試してみましょう

構文

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 Internationalization API Specification
# sec-Intl.ListFormat.prototype.resolvedoptions

ブラウザーの互換性

BCD tables only load in the browser

関連情報