JavaScript Array join() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Array to string

What You’ll Learn

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

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.

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.

📝 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.

⚡ Quick Reference

GoalCode
Default comma joinarr.join()
Custom separatorarr.join("-")
No separatorarr.join("")
Empty array""
Mutates array?No

📋 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

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.

JavaScript
const fruits = ["apple", "orange", "banana"];

console.log(fruits.join());
// "apple,orange,banana"
Try It Yourself

How It Works

Same result as fruits.toString() for most arrays—commas between each item.

Example 2 — Custom Separator with Hyphen

Pass any string as the glue between elements.

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

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

How It Works

The separator appears between items only—never before the first or after the last.

📈 Practical Patterns

Empty separator, URLs, and split inverse.

Example 3 — Empty String Separator (No Gap)

Join with "" to concatenate characters or tokens directly.

JavaScript
const letters = ["H", "i", "!"];

console.log(letters.join(""));
// "Hi!"

const numbers = [1, 2, 3, 4];
console.log(numbers.join(""));
// "1234"
Try It Yourself

How It Works

Numbers are coerced to strings automatically—no map(String) needed.

Example 4 — Build a URL Query String

Join key=value pairs with & for query parameters.

JavaScript
const queryParams = ["page=1", "limit=10", "sort=desc"];

const url = "https://example.com/data?" + queryParams.join("&");

console.log(url);
// "https://example.com/data?page=1&limit=10&sort=desc"
Try It Yourself

How It Works

Each param is already formatted; join("&") connects them. For real apps, consider URLSearchParams for encoding.

Example 5 — Inverse of split()

Split a string into an array, then join it back.

JavaScript
const original = "alpha,beta,gamma";

const parts = original.split(",");
const restored = parts.join(",");

console.log(parts);
// ["alpha", "beta", "gamma"]

console.log(restored);
// "alpha,beta,gamma"

console.log(restored === original);
// true
Try It Yourself

How It Works

Using the same separator for split and join round-trips simple CSV-style data. Edge cases (empty slots, encoding) need extra care.

🚀 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 wordswords.join(" ").
  • Character gluejoin("") 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.

📝 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.

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 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.join() Excellent

Bottom line: One of the most widely supported array methods. Safe everywhere.

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.

💡 Best Practices

✅ Do

  • Pick a separator that matches your output format
  • Use join(" ") for human-readable lists
  • Remember numbers stringify automatically
  • Pair with split when round-tripping strings
  • Use URLSearchParams for encoded query strings

❌ Don’t

  • Assume join mutates the array
  • Build URLs with join when values need encoding
  • Use join for deep object serialization (use JSON)
  • Forget empty arrays return ""
  • Rely on join for binary or complex data

Key Takeaways

Knowledge Unlocked

Five things to remember about Array.join()

Merge array elements into one string with control over separators.

5
Core concepts
📄 02

String

One result.

Output
📐 03

Default ,

Comma.

Separator
🔄 04

Coerces

To string.

Numbers OK
05

vs split

Inverse.

Pair

❓ Frequently Asked Questions

join() combines all array elements into one string, inserting a separator between each element. It returns a new string and does not change the array.
If you omit the separator or pass undefined, join() uses a comma (,). So [1, 2, 3].join() returns "1,2,3".
No. join() only reads the array and returns a string. The source array stays the same.
Yes. Each element is converted to a string before joining. [1, 2, 3].join("-") produces "1-2-3" without needing map(String).
join() is often the reverse of String.split(). "a,b,c".split(",") gives an array; ["a", "b", "c"].join(",") gives the string back.
join() is ES5 (2009). It works in all modern browsers and has been supported in Internet Explorer since early versions.
Did you know?

Array toString() is defined to behave like join(","). For any custom separator, use join explicitly instead of toString.

Continue to keys()

Learn how to get an iterator of array index keys for custom iteration patterns.

keys() 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