typedArray.toString
toString()方法返回一个表示指定数组及其元素的字符串。这个方法的算法和Array.prototype.toString()一样。TypedArray在这是typed array types之一。
语法
typedarray.toString()返回值
一个字符串,表示类型数组(typed array)的元素。
描述
TypedArray对象重写了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)The definition of 'TypedArray.prototype.toString' in that specification. | Standard | Initial definition. |
ECMAScript 2017 Draft (ECMA-262)The definition of 'Array.prototype.toString' in that specification. | Draft | |
浏览器兼容性
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) |
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

