Javascript - Array join() Method

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

Description

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 which is default to comma (,).

Syntax

array.join(separator)

Parameter Values

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

Return

A String, representing the array values, separated by the specified separator

Example

Join the elements of an array into a string:

Demo

var myArray = ["XML", "Json", "Database", "Mango"];
console.log(myArray.join());/*from   w  ww . ja  v  a  2 s  . c  o m*/

//Try using a different separator:

var myArray = ["XML", "Json", "Database", "Mango"];
console.log(myArray.join(" and "));

Result