Array.prototype.toString()

toString() 返回一个字符串,表示指定的数组及其元素。

语法

arr.toString()

返回值

一个表示指定的数组及其元素的字符串。

描述

ObjecttoString 方法。对于数组对象,toString 方法连接数组并返回一个字符串,其中包含用逗号分隔的每个数组元素。

当一个数组被作为文本值或者进行字符串连接操作时,将会自动调用其 toString 方法。

ECMAScript 5 semantics

从 JavaScript 1.8.5 (Firefox 4) 开始,和 ECMAScript 第5版语义(semantics)一致,toString() 方法是通用的,可被用于任何对象。将调用Object.prototype.toString(),并返回结果值。

规范

Specification Status Comment
ECMAScript 1st Edition (ECMA-262) Standard Initial definition. Implemented in JavaScript 1.1.
ECMAScript 5.1 (ECMA-262)
Array.prototype.toString
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
Array.prototype.toString
Standard  
ECMAScript Latest Draft (ECMA-262)
Array.prototype.toString
Draft  

浏览器兼容性

Update compatibility data on GitHub
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
toString Chrome Full support 1 Edge Full support 12 Firefox Full support 1 IE Full support 4 Opera Full support Yes Safari Full support Yes WebView Android Full support ≤37 Chrome Android Full support 18 Firefox Android Full support 4 Opera Android Full support Yes Safari iOS Full support Yes Samsung Internet Android Full support 1.0 nodejs Full support Yes

Legend

Full support  
Full support

相关链接