The toString()
method returns a string representing the specified array and its elements. This method has the same algorithm as Array.prototype.toString()
. TypedArray is one of the typed array types here.
The toString()
method returns a string representing the specified array and its elements. This method has the same algorithm as Array.prototype.toString()
. TypedArray is one of the typed array types here.
toString()
A string representing the elements of the typed array.
The TypedArray
objects override the toString
method of Object
. For TypedArray
objects, the toString
method joins the array and returns one string containing each typed array element separated by commas. For example, the following code creates a typed array and uses toString
to convert the array to a string.
const numbers = new Uint8Array([2, 5, 8, 1, 4]); numbers.toString(); // "2,5,8,1,4"
JavaScript calls the toString
method automatically when a typed array is to be represented as a text value or when an array is referred to in a string concatenation.
If a browser doesn't support the TypedArray.prototype.toString()
method yet, JavaScript will call the toString
method of Object
:
const numbers = new Uint8Array([2, 5, 8, 1, 4]); numbers.toString(); // "[object Uint8Array]"
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | Deno | Node.js | |
toString |
7 | 12 | 51 | 10 | 11.6 | 5.1 | ≤37 | 18 | 51 | 12 | 5 | 1.0 | 1.0 | 0.10.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/toString