Array.prototype.join()

Joins all array elements into a string separated by a delimiter.

Since ES1 Spec ↗

Syntax

arr.join(separator)

Parameters

NameTypeRequiredDescription
separator string No String placed between elements. Defaults to a comma ",".

Returns

string — A string with all elements joined; empty string if the array is empty.

Examples

console.log(['a', 'b', 'c'].join('-'));
Output
a-b-c
console.log([1, null, 2, undefined].join('|'));
Output
1||2|

Notes

null and undefined elements become empty strings. Does not mutate the array. Use `String.prototype.split` to reverse the operation.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also