JavaScriptArrays

Array.prototype.join()

Joins the array’s elements into a single string with a chosen separator.

Returns
A string made up of the array’s elements.
Changes the original
No
On this page

Example

#
JavaScript
const tags = ['html', 'css', 'javascript']

console.log(tags.join())
console.log(tags.join(', '))
console.log(tags.join(' · '))
console.log(['2026', '09', '28'].join('-'))
Console
html,css,javascript
html, css, javascript
html · css · javascript
2026-09-28

Definition and usage

#

The join() method turns every array element into text and glues them into one string. By default it separates them with a comma, but you can give any separator, including an empty string.

null and undefined values turn into empty strings, and nested arrays turn into comma-separated text.

It often pairs with split(): split() breaks a string into an array, join() glues an array back into a string.

Syntax

#
Syntax
array.join()
array.join(separator)

Parameters

#
  • separator

    optional

    The text inserted between elements. A comma by default.

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • To build a natural list in a sentence ("HTML, CSS, and JS"), Intl.ListFormat works better.
  • When building HTML from an array, remember join(""); otherwise, commas will show up between the elements.

Related entries

#

Spotted a mistake or missing an example? Write to us.