typedArray.toString() returns the elements as one string with commas between them. It gives exactly the same text as typedArray.join(","). JavaScript calls it for you whenever a typed array is used as text: with String(ta), with + and a string, and inside template strings. An empty typed array gives an empty string.
Remember
typedArray.toString() → "1,2,3"
ta.toString() === ta.join(",") → true
String(ta) → "1,2,3"
"Bytes: " + ta → "Bytes: 1,2,3"
(a template string does the same)
new Uint8Array(0).toString() → ""
Syntax
toString() takes no arguments. It always uses a comma as the separator.
JavaScript
typedArray.toString()
Call
What it does
ta.toString()
Get the elements as "1,2,3".
String(ta)
The same result, and it also works for values that could be null.
"Bytes: " + ta
Using the typed array as text calls toString() for you.
Built into JavaScript since ES2015 on all 11 typed array types. It is the very same function as Array.prototype.toString, which calls join().
Library declarations
JavaScript
TypedArray.prototype.toString() // returns a string
// same as ta.join(",")
// TypedArray.prototype.toString === Array.prototype.toString -> true
Parameters
Parameter
Description
(none)
toString() has no parameters. If you need another separator, use join(separator).
Return Value
Return Value
Description
String
The elements written as numbers and separated by commas, without spaces. An empty typed array gives "".
JavaScript Examples
Example 1 — toString() Is join With a Comma
A Uint8Array of three bytes is converted in two ways. Both give the same text, and both give a string.
Arrays inside a join. An Array of typed arrays is joined, and each item is turned into text with its own toString(): 1,2 and 3.
Negative numbers keep the sign. The Int16Array text is -4,25. The minus sign is part of the number text.
Back to a typed array.split(",") gives text pieces, Number converts each one, and Int16Array.from builds the array again.
Compatibility
Browser & Runtime Support
TypedArray.prototype.toString() is part of ES2015 (ES6), together with typed arrays and the other array-like methods.
✓ Baseline · ES2015
TypedArray.prototype.toString()
Supported in every modern browser, plus Node.js, Deno, and Bun.
98%Modern browser support
Google ChromeAll modern versions
Full support
Mozilla FirefoxAll modern versions
Full support
Apple SafariAll modern versions
Full support
Microsoft EdgeAll modern versions
Full support
Node.jsAll current releases
Supported
DenoAll releases
Supported
Internet ExplorerIE 10 and 11 have typed arrays, but not this method
Not supported
toString()Excellent
Bottom line: Safe everywhere modern JavaScript runs. Internet Explorer 10 and 11 have typed arrays but not this method, so convert with a plain Array there.
Frequently Asked Questions
A string of the elements separated by commas, such as "1,2,3". It is exactly the same as calling join(",") on the typed array.
Yes, toString() behaves like join(",") with the default comma. Use join(separator) when you want another separator, such as a space.
A template string converts the value to text, which calls toString(). The text is the comma-separated elements, for example Bytes: 1,2,3.
No. A Uint8Array and an Int16Array with the same numbers give the same text. To read the type name, use ta.constructor.name.
Use JSON.stringify(Array.from(ta)), which gives [1,2,3]. Calling JSON.stringify(ta) directly gives an object with index keys instead.