JavaScript join() Method
Example
Convert all elements in an array into a single string:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var energy = fruits.join();
energyOutput result:
Banana,Orange,Apple,Mango
Try it »
Definition and Usage
The join() method is used to convert all elements in an array into a string.
The elements are separated by the specified separator.
Browser support





All major browsers support the join() property.
Syntax
array
.join(
separator
)
Parameter value
| Parameters | Description |
|---|---|
| separator | Optional. Specifies the separator to use. If this parameter is omitted, a comma is used as the separator. |
Return Value
| Type | Description |
|---|---|
| String | Returns a string. This string is generated by converting each element of arrayObject into a string, concatenating those strings, and inserting the separator string between two elements. |
Technical Details
| JavaScript version: | 1.1 |
|---|
More examples
Example
Use different separators:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var energy = fruits.join(" and ");
energy Result output:
Banana and Orange and Apple and Mango
Try it »
JavaScript Array object