TypedArray.prototype.toLocaleString()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

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

試してみましょう

構文

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

引数

locales 省略可

BCP 47 言語タグの文字列か、その配列です。 locales 引数の一般的な形式と解釈については、 Intl メインページの引数の説明を参照してください。

options 省略可

構成プロパティを持つオブジェクトです。 Number.prototype.toLocaleString() を参照してください。

返値

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

解説

詳細については、 Array.prototype.toLocaleString() をご覧ください。このメソッドは汎用的ではなく、型付き配列インスタンスに対してのみ呼び出すことができます。

toLocaleString() の使用

js
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

関連情報