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.

TypedArray 实例的 toLocaleString() 方法返回一个表示类型化数组元素的字符串。使用 toLocaleString 方法将元素转换为字符串,并且这些字符串由特定于区域设置的字符串(例如逗号 ",")分隔。该方法与 Array.prototype.toLocaleString() 的算法相同。

¥The toLocaleString() method of TypedArray instances returns a string representing the elements of the typed array. The elements are converted to strings using their toLocaleString methods and these strings are separated by a locale-specific string (such as a comma ","). This method has the same algorithm as Array.prototype.toLocaleString().

Try it

语法

¥Syntax

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

参数

¥Parameters

locales Optional

带有 BCP 47 语言标记的字符串,或此类字符串的数组。有关 locales 论证的一般形式和解释,请参阅 Intl 主页参数说明

options Optional

具有配置属性的对象。参见 Number.prototype.toLocaleString()

返回值

¥Return value

表示类型化数组的元素的字符串。

¥A string representing the elements of the typed array.

描述

¥Description

详细信息请参见 Array.prototype.toLocaleString()。此方法不是通用的,只能在类型化数组实例上调用。

¥See Array.prototype.toLocaleString() for more details. This method is not generic and can only be called on typed array instances.

示例

¥Examples

使用 toLocaleString()

¥Using toLocaleString()

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

uint.toLocaleString();
// if run in a de-DE locale
// "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

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看