JavaScript Array join() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

Array.prototype.join(separator) builds one string from all elements, inserting separator between them. The default separator is a comma. It does not mutate the array. The common inverse is String.split().

Remember
array.join(separator)

["a", "b", "c"].join()       → "a,b,c"     // default ","
["a", "b", "c"].join("-")    → "a-b-c"
["a", "b", "c"].join("")     → "abc"
["a", "b", "c"].join(" / ")  → "a / b / c"

returns a string
array unchanged
null / undefined → empty slot in the string

Syntax

Call array.join. Start with this line.

JavaScript
array.join(separator = ",")
CallWhat it does
array.join(separator = ",")Primary signature.
array.join(...)Call with the arguments your case needs.

Built into JavaScript. Call join(...) on an array instance — no import required.

Library declarations
JavaScript
array.join(separator = ",")

Parameters

ParameterDescription
ArrayRequired. Elements to combine
separatorOptional. Text between elements (default ",")

Return Value

Return ValueDescription
*New string

JavaScript Examples

Example 1 — Default and Custom Separators

Omit the argument for commas, or pass your own separator.

JavaScript
const langs = ["JS", "Python", "Java"];

console.log(langs.join());       // "JS,Python,Java"
console.log(langs.join(" - "));  // "JS - Python - Java"
console.log(langs.join("|"));    // "JS|Python|Java"
Try It Yourself

How It Works

  1. Default comma. No argument → elements separated by ,.
  2. Custom text. " - " is inserted between each pair.
  3. Any string works. "|" is just another separator.
  4. Array unchanged. langs still holds three items.

Example 2 — Concatenate with join("")

An empty separator glues elements together with nothing between them.

JavaScript
const digits = ["2", "0", "2", "6"];
const word = ["C", "o", "d", "e"];

console.log(digits.join(""));  // "2026"
console.log(word.join(""));    // "Code"
console.log([1, null, 2].join("-"));  // "1--2"
Try It Yourself

How It Works

  1. Empty separator. Characters concatenate into one word/number string.
  2. Useful for digits. Join digit strings without commas.
  3. null becomes empty. You still get the surrounding separators → "1--2".
  4. Filter first if needed. Remove nulls before joining when gaps are unwanted.

Example 3 — Round-Trip with split()

Join to a string, then split back into an array.

JavaScript
const tags = ["js", "array", "join"];
const csv = tags.join(",");
const again = csv.split(",");

console.log(csv);                   // "js,array,join"
console.log(JSON.stringify(again)); // ["js","array","join"]
Try It Yourself

How It Works

  1. join builds CSV-style text. Commas separate the tags.
  2. split reverses it. Same separator rebuilds the array.
  3. Round-trip tip. Keep the separator out of the values themselves.
  4. Clear logging. JSON.stringify(again) shows the rebuilt array as text.

Browser & Runtime Support

Array.prototype.join() is part of ES5 (and existed earlier in practice). It is available in essentially all browsers and Node.js versions you will meet.

✓ Baseline · ES5

Array.prototype.join()

Supported in all modern browsers, Internet Explorer (legacy), and every current Node.js release.

99% Browser 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: Safe everywhere. Prefer join() over toString() when you need a custom separator.

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.
null and undefined become empty strings in the result. For example, [1, null, 2].join("-") returns "1--2".
array.toString() is like join() with a comma. Prefer join() when you want a custom separator.
String.split() splits a string into an array. join and split are common inverse partners.

Next: keys()

Get an iterator of an array’s indexes.

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.

11 people found this page helpful