JavaScript Array toString() Method

Beginner
⏱️ 7 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Comma string

What You’ll Learn

The toString() method converts an array into a comma-separated string. It is the default conversion when JavaScript needs a string from an array. This tutorial covers syntax, implicit coercion, mixed types, comparisons with join(), and five examples.

01

Syntax

toString()

02

Returns

String

03

Separator

Comma

04

Coercion

Auto-called

05

vs join

Custom sep

06

ES3

Universal

Introduction

Need a quick text snapshot of array contents? toString() joins every element with commas: "red,green,blue". It is simple, fast, and runs automatically when you concatenate an array with a string or embed it in a template literal.

The array itself is not changed—you always get a new string back. For custom separators or locale formatting, other methods are a better fit.

Understanding the toString() Method

array.toString() is defined to behave like array.join(","): each element is converted with its own toString(), then joined by a single comma with no spaces.

Empty slots in sparse arrays become empty string segments. null and undefined become empty strings in the joined result.

💡
Beginner Tip

console.log(arr) shows the array structure in devtools, but "Scores: " + arr uses toString() and prints Scores: 10,20,30.

📝 Syntax

General form of Array.prototype.toString:

JavaScript
array.toString()

Parameters

  • None.

Return value

  • A string of elements joined by commas.

Common patterns

  • arr.toString() — explicit conversion.
  • String(arr) or "" + arr — implicit toString.
  • `Values: ${arr}` — template literal coercion.
  • arr.join(" | ") — custom separator instead.
  • JSON.stringify(arr) — JSON text for data/logging.

⚡ Quick Reference

GoalCode
Comma-separated stringarr.toString()
Custom separatorarr.join(" - ")
Locale formattingarr.toLocaleString()
JSON textJSON.stringify(arr)
Same as join(",")arr.toString() === arr.join()
Mutates array?No

📋 toString() vs join() vs toLocaleString() vs JSON.stringify()

All return strings; pick based on separator, locale, or data format needs.

toString
comma join

Default

join
any sep

Flexible

toLocaleString
locale

i18n

JSON.stringify
JSON

Data

Examples Gallery

Open DevTools Console (F12) or use Try-it labs. Example N maps to ?tryit=N.

📚 Getting Started

Basic comma-separated output.

Example 1 — Convert Strings to One Line

Classic color list joined by commas.

JavaScript
const colors = ["red", "green", "blue", "yellow"];

const text = colors.toString();

console.log(text);
// "red,green,blue,yellow"
Try It Yourself

How It Works

Each string stays as-is; commas glue them together with no spaces.

Example 2 — Number Array to String

Numbers convert to their default string form (no locale grouping).

JavaScript
const temps = [25, 30, 22, 18, 27];

console.log(`Today's temperatures: ${temps.toString()}`);
// "Today's temperatures: 25,30,22,18,27"
Try It Yourself

How It Works

For locale-aware number formatting (commas in thousands), use toLocaleString() instead.

📈 Practical Patterns

Implicit calls, custom separators, and object pitfalls.

Example 3 — Implicit toString() in Concatenation

JavaScript calls toString() when mixing array + string.

JavaScript
const days = ["Mon", "Tue", "Wed"];

console.log("Days: " + days);
// "Days: Mon,Tue,Wed"

console.log(String(days));
// "Mon,Tue,Wed"
Try It Yourself

How It Works

The + operator with a string triggers ToString on the array, which invokes Array.prototype.toString.

Example 4 — toString() vs join()

Need readable spacing? Use join with a custom separator.

JavaScript
const colors = ["red", "green", "blue"];

console.log(colors.toString());
// "red,green,blue"

console.log(colors.join(" | "));
// "red | green | blue"
Try It Yourself

How It Works

toString() equals join(","). For anything other than commas, call join directly.

Example 5 — Object Arrays Show [object Object]

Plain toString() is not useful for object data.

JavaScript
const users = [{ name: "Alice" }, { name: "Bob" }];

console.log(users.toString());
// "[object Object],[object Object]"

console.log(users.map((u) => u.name).join(", "));
// "Alice, Bob"
Try It Yourself

How It Works

Objects lack a meaningful default string. Map to the fields you need, or use JSON.stringify for structured output.

🚀 Common Use Cases

  • Quick logging — one-line array snapshot in console messages.
  • Template messages — embed lists in alert or label text.
  • Legacy APIs — endpoints expecting comma-separated values.
  • Debugging — fast string glance at primitive arrays.
  • Implicit UI — know that "" + arr uses this method.
  • When not to use — objects, nested data, or locale numbers.

🧠 How toString() Runs

1

Visit each index

Empty slots become empty strings.

Loop
2

Element.toString()

Each value converts to string form.

Convert
3

Join with comma

Same as join(",") with no spaces.

Join
4

Return string

Array unchanged.

📝 Notes

  • Does not mutate the array.
  • Equivalent to join(",") (no spaces after commas).
  • Called implicitly during string coercion.
  • No locale formatting—numbers stay plain (1000000 not 1,000,000).
  • Objects become [object Object].
  • For nested or structured data, use JSON.stringify.
  • ES3—universal browser support.

Browser & Runtime Support

Array.prototype.toString() has been available since ES3 and is one of the most widely supported JavaScript methods.

Baseline · ES3

Array.prototype.toString()

Supported in every browser and Node.js version—including very old environments. Behavior is identical across platforms.

100% Universal support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Array.toString() Excellent

Bottom line: Safe everywhere. Remember its limits with objects and locale-sensitive numbers.

Conclusion

toString() is the simplest way to flatten a primitive array into a comma-separated string. JavaScript calls it automatically in many string contexts. For custom separators use join(); for locale rules use toLocaleString().

Next, learn unshift() to add elements at the start of an array.

💡 Best Practices

✅ Do

  • Use for quick primitive array display
  • Know implicit coercion happens with + strings
  • Use join when you need custom separators
  • Map object fields before joining for readable text
  • Prefer JSON.stringify for structured logs

❌ Don’t

  • Expect meaningful output from object arrays
  • Use for locale number formatting
  • Parse the string back into an array (use JSON)
  • Assume spaces appear after commas
  • Confuse display strings with data storage

Key Takeaways

Knowledge Unlocked

Five things to remember about Array.toString()

Comma-join elements into one string.

5
Core concepts
💬 02

Comma join

No spaces.

Format
03

Coercion

Auto-called.

Implicit
🔗 04

vs join

Custom sep.

Compare
📦 05

Objects

[object Object].

Trap

❓ Frequently Asked Questions

toString() converts an array to a comma-separated string by calling toString on each element and joining with commas. It returns a string and does not mutate the array.
No. toString() only reads the array and returns a new string. The original array is unchanged.
Array.toString() is equivalent to join() with no arguments, which defaults to a comma separator. Use join(' | ') or any other delimiter when you need a custom separator.
When an array is coerced to a string—such as in template literals, string concatenation ('Values: ' + arr), or String(arr)—JavaScript calls the array's toString method.
Each object converts with Object.prototype.toString, which returns '[object Object]'. Use JSON.stringify, map, or a formatter for meaningful object output—not plain toString().
Array.toString() has been available since ES3 and works in every browser and Node.js environment.
Did you know?

Array.prototype.toString explicitly delegates to this.join() with no arguments, and join() defaults to a comma. That is why [1, 2].toString() === "1,2" and matches [1, 2].join().

Continue to unshift()

Learn how to add one or more elements at the beginning of an array.

unshift() 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.

6 people found this page helpful