THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

JavaScript Array join() Method

JavaScript Array Reference JavaScript Array Reference

Example

Join the elements of an array into a string:

var fruits = ["Banana", "Orange", "Apple", "Mango"];
var energy = fruits.join();

The result of energy will be:

Banana,Orange,Apple,Mango
Try it yourself »

More "Try it Yourself" examples below.


Definition and Usage

The join() method joins the elements of an array into a string, and returns the string.

The elements will be separated by a specified separator. The default separator is comma (,).


Browser Support

The numbers in the table specify the first browser version that fully supports the method.

Method
join() 1.0 5.5 1.0 Yes Yes

Syntax

array.join(separator)

Parameter Values

Parameter Description
separator Optional. The separator to be used. If omitted, the elements are separated with a comma

Technical Details

Return Value: A String, representing the array values, separated by the specified separator
JavaScript Version: 1.1

Examples

More Examples

Example

Try using a different separator:

var fruits = ["Banana", "Orange", "Apple", "Mango"];
var energy = fruits.join(" and ");

The result of energy will be:

Banana and Orange and Apple and Mango
Try it yourself »

JavaScript Array Reference JavaScript Array Reference