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
Fundamentals
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.
Concept
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.
Foundation
📝 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.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Comma-separated string
arr.toString()
Custom separator
arr.join(" - ")
Locale formatting
arr.toLocaleString()
JSON text
JSON.stringify(arr)
Same as join(",")
arr.toString() === arr.join()
Mutates array?
No
Compare
📋 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
Hands-On
Examples Gallery
Open DevTools Console (F12) or use Try-it labs. Example N maps to ?tryit=N.
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.
Important
📝 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.
Compatibility
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 ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
Array.toString()Excellent
Bottom line: Safe everywhere. Remember its limits with objects and locale-sensitive numbers.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Array.toString()
Comma-join elements into one string.
5
Core concepts
📝01
Syntax
toString()
API
💬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().