TypedArray.prototype.toLocaleString()

toLocaleString() メソッドは、型付き配列の要素を表す文字列を返します。要素は文字列に変換され、ロケール依存の文字列(カンマ "," など)で区切られます。このメソッドは Array.prototype.toLocaleString() と同じアルゴリズムを持ち、型付き配列の要素は数値なので、各要素に対して Number.prototype.toLocaleString() と同じアルゴリズムが適用されます。ここで TypedArray型付き配列型の 1 つです。

試してみましょう

構文

toLocaleString()
toLocaleString(locales)
toLocaleString(locales, options)

引数

localesoptions の引数は、関数の動作をカスタマイズし、アプリケーションが整形規則を使用する言語を指定できるようにします。 localesoptions の引数を無視する実装では、使用されるロケールと返される文字列の形式は完全に実装に依存します。

これらの引数の詳細および使用方法については、 Intl.NumberFormat() コンストラクターを参照してください。

返値

型付き配列の要素を表す文字列。

toLocaleString の使用

const uint = new Uint32Array([2000, 500, 8123, 12, 4212]);

uint.toLocaleString();
// de-DE ロケールで実行している場合
// "2.000,500,8.123,12,4.212"

uint.toLocaleString("en-US");
// "2,000,500,8,123,12,4,212"

uint.toLocaleString("ja-JP", { style: "currency", currency: "JPY" });
// "¥2,000,¥500,¥8,123,¥12,¥4,212"

仕様書

Specification
ECMAScript Language Specification
# sec-%typedarray%.prototype.tolocalestring

ブラウザーの互換性

BCD tables only load in the browser

関連情報