非常教程

JavaScript参考手册

TypedArray

typedArray.toString

toString()方法返回一个表示指定数组及其元素的字符串。这个方法的算法和Array.prototype.toString()一样。TypedArray在这是typed array types之一。

语法

typedarray.toString()

返回值

一个字符串,表示类型数组(typed array)的元素。

描述

TypedArray对象重写了ObjecttoString方法。对 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 将调用ObjecttoString方法:

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)

JavaScript

JavaScript 是一种高级编程语言,通过解释执行,是一门动态类型,面向对象(基于原型)的解释型语言。它已经由ECMA(欧洲电脑制造商协会)通过 ECMAScript 实现语言的标准化。它被世界上的绝大多数网站所使用,也被世界主流浏览器( Chrome、IE、FireFox、Safari、Opera )支持。JavaScript 是一门基于原型、函数先行的语言,是一门多范式的语言,它支持面向对象编程,命令式编程,以及函数式编程。它提供语法来操控文本、数组、日期以及正则表达式等,不支持 I/O,比如网络