Array.prototype.join()

join(separator)
Returns: string · Updated March 13, 2026 · Array Methods
array join string

The join() method concatenates all elements of an array into a single string. By default, elements are separated by a comma (,), but you can specify a custom separator as the first argument.

Syntax

join()
join(separator)

Parameters

ParameterTypeDefaultDescription
separatorstring","The string to separate each element. If omitted, elements are separated by a comma.

Examples

Basic usage

const fruits = ["apple", "banana", "cherry"];
console.log(fruits.join());
// "apple,banana,cherry"

console.log(fruits.join(" - "));
// "apple - banana - cherry"

Building HTML

const items = ["li", "li", "li"];
console.log("<ul>" + items.join("") + "</ul>");
// "<ul><li></li><li></li><li></li></ul>"

Converting numbers to formatted strings

const numbers = [1, 2, 3, 4, 5];
console.log(numbers.join("|"));
// "1|2|3|4|5"

Empty array

const empty = [Global_Objects::eval];
console.log(empty.join(","));
// ""

Common Patterns

CSV generation

const data = ["name", "age", "city"];
console.log(data.join(","));
// "name,age,city"

URL query strings

const params = ["page=1", "limit=10", "sort=date"];
console.log("?" + params.join("&"));
// "?page=1&limit=10&sort=date"

See Also

Performance Considerations

The method creates a new string by iterating through the array once. For small to medium arrays, this is negligible, but for very large arrays with thousands of elements, consider alternatives like streaming or incremental building.

Comparing with reduce

While you can use to achieve similar results, is optimized specifically for string concatenation and is typically faster:

Handling different types

automatically converts all elements to strings using their method:

Note how and become empty strings in the output.

Working with nested arrays

For deeply nested arrays, flatten first using :

Edge Cases

  • Empty array: Returns an empty string
  • Single element: Returns that element as a string (no separator)
  • Undefined elements: Converted to empty strings
  • Objects: Use or map first