JavaScript Array join() Method


The JavaScript array join() method combines all the elements of an array into a string and return a new string. We can use any type of separators to separate given array elements.

Javascript array join() method joins all the elements of an array into a string.

Syntax

array.join(separator)

Parameter Details

separator − Specifies a string to separate each element of the array. If omitted, the array elements are separated with a comma.

Example

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

Example -