JavaScript TypedArray toLocaleString() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
ES2015

Definition

typedArray.toLocaleString(locales, options) returns a string with the elements written for a locale, which means a language and region such as "en-US" or "de-DE". Each element is formatted like Number.prototype.toLocaleString does, so separators follow the locale. The formatted elements are joined with a comma. Pass the locale yourself when the output must be the same everywhere.

Remember
typedArray.toLocaleString(locale, options)

new Int32Array([1000, 25000]).toLocaleString('en-US')   → "1,000,25,000"
new Int32Array([1000, 25000]).toLocaleString('de-DE')   → "1.000,25.000"

options: { style: 'currency', currency: 'USD' }
         { style: 'percent' }

elements are joined with ","

Syntax

Both arguments are optional. Without a locale, the default locale of the computer is used.

JavaScript
typedArray.toLocaleString()
typedArray.toLocaleString(locales)
typedArray.toLocaleString(locales, options)
CallWhat it does
ta.toLocaleString("en-US")American style: 1,234.5, comma for thousands, dot for decimals.
ta.toLocaleString("de-DE")German style: 1.234,5, dot for thousands, comma for decimals.

Built into JavaScript since ES2015 on all 11 typed array types. Options work like Intl.NumberFormat.

Library declarations
JavaScript
TypedArray.prototype.toLocaleString(locales, options)   // returns a string

// each element: element.toLocaleString(locales, options)
// joined with ","; empty typed array -> ""

Parameters

ParameterDescription
locales (optional)A locale name such as "en-US" or "de-DE", or a list of them. If it is missing, the default locale of the environment is used.
options (optional)An object with number format options, such as style, currency, and minimumFractionDigits.

Return Value

Return ValueDescription
StringThe elements formatted for the locale and joined with commas. It is the same idea as Array toLocaleString().

JavaScript Examples

Example 1 — One Typed Array, Two Locales

Whole-number sales figures are formatted for the United States and for Germany.

JavaScript
const sales = new Int32Array([-1500, 25000, 3000000]);

console.log(sales.toLocaleString('en-US'));   // -1,500,25,000,3,000,000
console.log(sales.toLocaleString('de-DE'));   // -1.500,25.000,3.000.000

console.log(sales.join());                    // -1500,25000,3000000
Try It Yourself

How It Works

  1. US style groups with commas. With "en-US" each number gets a comma every three digits, for example 3,000,000.
  2. German style groups with dots. With "de-DE" the group separator is a dot, so the same number is 3.000.000.
  3. The list comma never changes. The numbers are joined with a plain comma in both lines. Plain join() shows the raw numbers.

Example 2 — Currency and Percent Options

Prices and discounts live in a Float64Array. An options object says how to write each number.

JavaScript
const prices = new Float64Array([1234.5, 0.5, 99]);
const usd = { style: 'currency', currency: 'USD' };

console.log(prices.toLocaleString('en-US', usd));   // $1,234.50,$0.50,$99.00

const rates = new Float64Array([0.256, 0.5, 1]);
console.log(rates.toLocaleString('en-US', { style: 'percent' }));   // 26%,50%,100%
Try It Yourself

How It Works

  1. Currency adds sign and cents. With style: "currency" each price gets a dollar sign and exactly two decimals: 1234.5 becomes $1,234.50.
  2. Percent multiplies by 100. The rate 0.5 becomes 50% and 1 becomes 100%. The rate 0.256 is rounded to 26%.
  3. One options object for all. The same options apply to every element, and the results are still joined with a comma.

Example 3 — Fraction Digits and Per-Element Formatting

By default at most three decimals are shown. We fix them, and format each element separately.

JavaScript
const distances = new Float64Array([1234.5678, 1.23456, 99]);

const us = Array.from(distances, (n) => n.toLocaleString('en-US'));
console.log(us.join(' | '));       // 1,234.568 | 1.235 | 99

const fixed = { minimumFractionDigits: 2, maximumFractionDigits: 2 };
const de = Array.from(distances, (n) => n.toLocaleString('de-DE', fixed));
console.log(de.join(' | '));       // 1.234,57 | 1,23 | 99,00
console.log(distances.toLocaleString('en-US', fixed));   // 1,234.57,1.23,99.00
Try It Yourself

How It Works

  1. Three decimals at most. Without options, 1234.5678 is rounded to 1,234.568 and 1.23456 to 1.235. The whole number 99 stays 99.
  2. Fixed decimals for tidy columns. A minimum and maximum of 2 give exactly two decimals, and German style uses a comma for them: 99,00.
  3. Formatting by hand gives control. Array.from with a callback formats each element, so the separator can be anything, here " | ".

Browser & Runtime Support

TypedArray.prototype.toLocaleString() is part of ES2015 (ES6). The locales and options arguments use the Intl number formatting built into modern browsers.

✓ Baseline · ES2015

TypedArray.prototype.toLocaleString()

Supported in every modern browser, plus Node.js, Deno, and Bun.

98% Modern browser support
Google Chrome All modern versions
Full support
Mozilla Firefox All modern versions
Full support
Apple Safari All modern versions
Full support
Microsoft Edge All modern versions
Full support
Node.js All current releases
Supported
Deno All releases
Supported
Internet Explorer IE 10 and 11 have typed arrays, but not this method
Not supported
toLocaleString() Excellent

Bottom line: Safe everywhere modern JavaScript runs. The exact text depends on the locale data, so always pass the locale. Internet Explorer 10 and 11 lack this method.

Frequently Asked Questions

A string with each element formatted for a locale, joined by commas. With "en-US" 1234.5 becomes 1,234.5, and with "de-DE" it becomes 1.234,5.
Without a locale argument it uses the default locale of the computer or browser. Pass an explicit locale such as "en-US" for the same text everywhere.
Yes. Pass options such as { style: "currency", currency: "USD" } and every element is written like $1,234.50.
The elements are always joined with a plain comma, whatever the locale. Format each element with Array.from and join it yourself for another separator.
toString() writes plain numbers like 1234.5. toLocaleString() formats them for a locale.

Next: toReversed()

Get a reversed copy of the typed array and keep the original order.

toReversed() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful