HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

JavaScript Array join() Method

Array Object Reference JavaScript Array Object

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 »

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

Internet Explorer Firefox Opera Google Chrome Safari

The join() method is supported in all major browsers.


Syntax

array.join(separator)

Parameter Values

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

Return Value

Type Description
String The array values, separated by the specified separator

Technical Details

JavaScript Version: 1.1


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 »

Array Object Reference JavaScript Array Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE