首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

array.toString

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

代码语言:javascript
复制
var months = ['Jan', 'Feb', 'Mar', 'Apr'];
months.toString(); // "Jan,Feb,Mar,Apr"

语法

代码语言:javascript
复制
arr.toString()

返回值

表示数组元素的字符串。

描述

Array对象覆盖了 ObjecttoString方法。对于数组对象,toString方法返回一个字符串,该字符串由数组中的每个元素的toString()返回值经调用 join()方法连接(由逗号隔开)组成。例如,下面的代码创建了一个数组,然后使用toString方法把该数组转成一个字符串。

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

ECMAScript 5 semantics

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

规范

Specification

Status

Comment

ECMAScript 1st Edition (ECMA-262)

Standard

Initial definition. Implemented in JavaScript 1.1.

ECMAScript 5.1 (ECMA-262)The definition of 'Array.prototype.toString' in that specification.

Standard

ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Array.prototype.toString' in that specification.

Standard

ECMAScript Latest Draft (ECMA-262)The definition of 'Array.prototype.toString' in that specification.

Living Standard

浏览器兼容性

Feature

Chrome

Edge

Firefox

Internet Explorer

Opera

Safari

Basic Support

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

Feature

Android

Chrome for Android

Edge mobile

Firefox for Android

IE mobile

Opera Android

iOS Safari

Basic Support

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

扫码关注腾讯云开发者

领取腾讯云代金券