Array.prototype.join()
Joins all array elements into a string separated by a delimiter.
Syntax
arr.join(separator) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
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
| Environment | Since version |
|---|---|
| chrome | 1.0 |
| firefox | 1.0 |
| safari | 1.0 |
| edge | 12 |
| node | 0.10 |