JavaScript TypedArray toString() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
ES2015

Definition

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()
CallWhat 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: " + taUsing 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

ParameterDescription
(none)toString() has no parameters. If you need another separator, use join(separator).

Return Value

Return ValueDescription
StringThe 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.

JavaScript
const bytes = new Uint8Array([1, 2, 3]);

console.log(bytes.toString());                    // 1,2,3
console.log(bytes.toString() === bytes.join(','));   // true
console.log(typeof bytes.toString());             // string
console.log('[' + new Uint8Array(0).toString() + ']');   // []
Try It Yourself

How It Works

  1. Commas without spaces. The text is 1,2,3. The method has no way to add a space, so there is none.
  2. An exact match with join. Comparing with bytes.join(",") gives true, because they build the same string.
  3. Zero elements give zero text. The empty typed array returns an empty string, which the brackets show as [].

Example 2 — JavaScript Calls toString() for You

Pixel values in a Uint8Array are put into messages with + and String(). No explicit call is needed, but the result is the same.

JavaScript
const pixels = new Uint8Array([200, 150, 100]);

console.log('Pixels: ' + pixels);                  // Pixels: 200,150,100
console.log(String(pixels));                       // 200,150,100
console.log(String(pixels) === pixels.toString());  // true
console.log(('' + pixels).length);                 // 11
Try It Yourself

How It Works

  1. Plus with text converts. In "Pixels: " + pixels, JavaScript needs a string, so it calls the typed array's toString() behind the scenes.
  2. String() does the same. String(pixels) gives the same text as the explicit method call, so the comparison is true.
  3. The length counts commas. 200,150,100 has nine digits and two commas, which is 11 characters.

Example 3 — Typed Arrays Inside Lists, and Back Again

Several small typed arrays can be joined as a table row. A split and Number turn the text back into a typed array.

JavaScript
const rows = [new Uint8Array([1, 2]), new Uint8Array([3])];
console.log(rows.join(' | '));               // 1,2 | 3

const text = new Int16Array([-4, 25]).toString();
console.log(text);                           // -4,25

const restored = Int16Array.from(text.split(','), Number);
console.log(restored.join(' '));             // -4 25
console.log(Object.prototype.toString.call(restored).slice(8, -1));   // Int16Array
Try It Yourself

How It Works

  1. 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.
  2. Negative numbers keep the sign. The Int16Array text is -4,25. The minus sign is part of the number text.
  3. Back to a typed array. split(",") gives text pieces, Number converts each one, and Int16Array.from builds the array again.

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 Chrome All modern versions
Full support
Mozilla Firefox All modern versions
Full support
Apple Safari All modern versions
Full support
Microsoft Edge All modern versions
Full support
Node.js All current releases
Supported
Deno All releases
Supported
Internet Explorer IE 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.

Next: values()

Get an iterator over the elements, the one that for...of uses.

values() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful