概述
toLocaleString() 返回一个字符串表示数组中的元素。数组中的元素将使用各自的 toLocaleString 方法转成字符串,这些字符串将使用一个特定语言环境的字符串(例如一个逗号 ",")隔开。
语法
arr.toLocaleString();
描述
数组中的元素将会使用各自的 toLocaleString 方法:
Object:Object.prototype.toLocaleString()Number:Number.prototype.toLocaleString()Date:Date.prototype.toLocaleString()
示例
例子:使用 toLocaleString
var number = 1337; var date = new Date(); var myArr = [number, date, "foo"]; var str = myArr.toLocaleString(); console.log(str); // 输出 "1337,2015/2/27 下午8:29:04,foo" // 假定运行在中文(zh-CN)环境,北京时区
规范
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 3rd Edition. | Standard | Initial definition. |
| ECMAScript 5.1 (ECMA-262) Array.prototype.toLocaleString |
Standard | |
| ECMAScript 6 (ECMA-262) Array.prototype.toLocaleString |
Release Candidate |
浏览器兼容性
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |