toLocaleString()
方法返回一个字符串,表明该类型化数组的元素。这些元素被转化为字符串并由一个区域设置指定的分隔符(例如逗号 “,”)分隔。这个方法与Array.prototype.toLocaleString()
拥有相同的算法。同时,由于类型化数组的元素都是数,将每个元素转化为字符串的算法与Number.prototype.toLocaleString()
是相同的。(类型化数组)的是typed array types中的其中一个。
语法
typedarray.toLocaleString([locales [, options]]);
参数
返回值
一个字符串,表明该类型化数组内的元素。
例子
使用toLocaleString
var 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"
规范
规范 | 状态 | 说明 |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) TypedArray.prototype.toLocaleString |
Standard | 初始定义。 |
ECMAScript (ECMA-262) TypedArray.prototype.toLocaleString |
Living Standard |
浏览器兼容性
BCD tables only load in the browser
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.