Array.prototype.toString()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
toString()
方法將回傳一個可以表達該陣列及其元素的字串。
嘗試一下
const array1 = [1, 2, "a", "1a"];
console.log(array1.toString());
// Expected output: "1,2,a,1a"
語法
js
toString()
回傳值
一個表達該陣列及該陣列中元素的字串。
描述
ECMAScript 5 語義
始於 JavaScript 1.8.5 (Firefox 4),並且和 ECMAScript 5 的語義一致。
toString()
方法是通用的,任何的物件都可以使用。 Object.prototype.toString()
會被呼叫,並回傳結果。
範例
如何使用 toString
js
const array1 = [1, 2, "a", "1a"];
console.log(array1.toString());
// expected output: "1,2,a,1a"
規範
Specification |
---|
ECMAScript® 2025 Language Specification # sec-array.prototype.tostring |
瀏覽器相容性
BCD tables only load in the browser