JavaScript join()Method
Examples
Convert all elements in an array to a string:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var energy = fruits.join();
var energy = fruits.join();
energyOutput:
Banana,Orange,Apple,Mango
Try it Yourself »
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 Values
| Parameter | Description |
|---|---|
| separator | Optional. Specifies the separator to use. If this parameter is omitted, the comma is used as the separator. |
Return Value
| Type | Description |
|---|---|
| String | Returns a string. The string is generated by converting each element of arrayObject to a string, then concatenating these strings, inserting the separator string between two elements. |
Technical Details
| JavaScript Version: | 1.1 |
|---|
More Examples
Examples
Use different separators:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var energy = fruits.join(" and ");
var energy = fruits.join(" and ");
energyOutput:
Banana and Orange and Apple and Mango
Try it Yourself »
Other Extensions
JavaScript Array Object