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 2017年1月.
toLocaleString() は TypedArray インスタンスのメソッドで、型付き配列の要素を表す文字列を返します。要素は toLocaleString メソッドを使用して文字列に変換され、これらの文字列はロケール依存の文字列(カンマ "," など)で区切られます。このメソッドは Array.prototype.toLocaleString() と同じアルゴリズムです。
試してみましょう
const uint8 = new Uint32Array([500, 8123, 12]);
console.log(uint8.toLocaleString());
// Expected output: "500,8123,12"
console.log(uint8.toLocaleString("en-GB"));
// Expected output: "500,8,123,12"
console.log(
uint8.toLocaleString("de-DE", { style: "currency", currency: "EUR" }),
);
// Expected output: "500,00 €,8.123,00 €,12,00 €"
構文
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® 2026 Language Specification> # sec-%typedarray%.prototype.tolocalestring> |
ブラウザーの互換性
Loading…