toString()方法返回一个表示指定数组及其元素的字符串。这个方法的算法和Array.prototype.toString()一样。TypedArray 在这是typed array types 之一。
语法
typedarray.toString()
返回值
一个字符串,表示类型数组(typed array)的元素。
描述
Object的 toString方法。对 TypedArray 对象来说,toString 方法联结了数组,并返回一个字符串,它包含由逗号分隔的数组元素。例如,下面的代码创建了一个类型数组,使用toString 将数组转化为字符串。
var numbers = new Uint8Array([2, 5, 8, 1, 4]) numbers.toString(); // "2,5,8,1,4"
当一个类型数组表示为文本值,或者当一个数组被用于字符串连接,则JavaScript 将自动调用 toString 方法。
兼容性
如果浏览器还不支持TypedArray.prototype.toString() 方法,JavaScript 将调用Object的 toString 方法:
var numbers = new Uint8Array([2, 5, 8, 1, 4]) numbers.toString(); // "[object Uint8Array]"
规范
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 2015 (6th Edition, ECMA-262) TypedArray.prototype.toString |
Standard | 初始定义 |
| ECMAScript Latest Draft (ECMA-262) Array.prototype.toString |
Draft |
浏览器兼容性
We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains.
Find out how you can help!
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | (Yes) | 51 (51) | (Yes) | (Yes) | (Yes) |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | 51.0 (51) | (Yes) | (Yes) | (Yes) |