Array.prototype.toString()
toString()
返回一个字符串,表示指定的数组及其元素。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
语法
arr.toString()
返回值
一个表示指定的数组及其元素的字符串。
描述
Array
对象覆盖了Object
的 toString
方法。对于数组对象,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 (ECMA-262) Array.prototype.toString |
Living Standard |
浏览器兼容性
BCD tables only load in the browser