The join() method turns an array into a single string, placing a separator between elements. Default separator is a comma. This tutorial covers syntax, five examples, URL query building, the inverse relationship with split(), and how join() compares to toString().
01
Syntax
join(sep?)
02
Default
Comma
03
String out
New string
04
Coerces
To string
05
vs split
Inverse
06
ES5
Wide support
Fundamentals
Introduction
Arrays hold lists; strings display them. The join() method bridges that gap—turn tags into a CSV line, path segments into a URL, or words into a sentence with spaces.
It returns a new string and leaves the array unchanged. Each element is converted to a string automatically, so numbers work without extra steps.
Concept
Understanding the join() Method
array.join(separator) walks every slot from index 0 to length - 1, converts each value to a string, and inserts separator between adjacent items.
Omit the separator (or pass undefined) and you get commas. Pass "" to glue elements with nothing in between.
💡
Beginner Tip
join() is the array counterpart of String.split(). Split breaks a string into pieces; join merges pieces back into one string.
Foundation
📝 Syntax
General form of Array.prototype.join:
JavaScript
array.join(separator)
Parameters
separator — optional string placed between elements (default ",").
Return value
A single string built from all elements.
Empty array returns "".
Original array unchanged.
Common patterns
arr.join() — comma-separated (default).
arr.join(" ") — space-separated words.
arr.join("") — concatenate with no separator.
params.join("&") — build query strings.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Default comma join
arr.join()
Custom separator
arr.join("-")
No separator
arr.join("")
Empty array
""
Mutates array?
No
Compare
📋 join() vs toString() vs split() vs template literals
Pick join when you need a configurable separator between all elements.
join
custom sep
Flexible glue
toString
comma only
Like join()
split
string → array
Inverse
template
`${a} ${b}`
Few items
Hands-On
Examples Gallery
Open DevTools Console (F12) or use Try-it labs. Example N maps to ?tryit=N.
📚 Getting Started
Default and custom separators.
Example 1 — Default Comma Separator
Calling join() with no argument uses commas between elements.
Using the same separator for split and join round-trips simple CSV-style data. Edge cases (empty slots, encoding) need extra care.
Applications
🚀 Common Use Cases
Display lists — “Milk, Bread, Eggs” for UI text.
Path building — join segments with / (mind leading slashes).
Query strings — connect key=value pairs with &.
CSV export — comma or tab separated rows.
Sentence from words — words.join(" ").
Character glue — join("") for passwords or codes.
🧠 How join() Runs
1
Pick separator
Default comma if omitted or undefined.
Config
2
Convert elements
Each slot becomes a string via ToString.
Coerce
3
Insert separators
Glue between items, not at ends.
Build
4
📄
Return string
Array unchanged; output is one string.
Important
📝 Notes
Default separator is "," (comma).
Empty array → "" (empty string).
Elements are stringified; numbers work out of the box.
Sparse holes become empty strings in the result.
null and undefined become "" when joined.
ES5—universal browser support.
Compatibility
Browser & Runtime Support
Array.prototype.join() has been available since early JavaScript and is part of ES5. It works in every browser environment.
✓ Baseline · ES5
Array.prototype.join()
Supported in all browsers including IE 6+, and all modern Node.js versions.
99%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.join()Excellent
Bottom line: One of the most widely supported array methods. Safe everywhere.
Wrap Up
Conclusion
join() is the straightforward way to turn array elements into readable text. Choose your separator deliberately: commas for defaults, spaces for sentences, empty string for direct concatenation.
Next, explore keys() to iterate over array index names as an iterator.