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 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.
Syntax
typedarray.toString()
Return value
A string representing the elements of the typed array.
Examples
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.
var 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.
Compatibility
If a browser doesn't support the TypedArray.prototype.toString()
method yet, JavaScript will call the toString
method of Object
:
var numbers = new Uint8Array([2, 5, 8, 1, 4]) numbers.toString(); // "[object Uint8Array]"
Specifications
Specification |
---|
ECMAScript (ECMA-262) The definition of 'Array.prototype.toString' in that specification. |
Browser compatibility
Desktop | Mobile | Server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
toString | Chrome Full support 7 | Edge Full support 12 | Firefox Full support 51 | IE Full support 10 | Opera Full support 11.6 | Safari Full support 5.1 | WebView Android Full support ≤37 | Chrome Android Full support 18 | Firefox Android Full support 51 | Opera Android Full support 12 | Safari iOS Full support 5 | Samsung Internet Android Full support 1.0 | nodejs Full support 0.10 |
Legend
- Full support
- Full support