Open In App

JavaScript Array join() Function

The JavaScript Array.join() method is used to join the elements of the array together into a string. The elements of the string will be separated by a specified separator and its default value is a comma(, ).

Syntax:



Array.join([separator])

Parameters: 

Return Value:



Example 1: In this example, we will be joining the elements of an array using ( | ) by join() method.




function func() {
    let a = [1, 2, 3, 4, 5, 6];
    console.log(a.join('|'));
}
 
func();

Output
1|2|3|4|5|6

Example 2: In this example, the function join() joins together the elements of the array into a string using ‘, ‘ since it is the default value.




function func() {
    let a = [1, 2, 3, 4, 5, 6];
    console.log(a.join());
}
 
func();

Output
1,2,3,4,5,6

Example 3: In this example, the function join() joins together the elements of the array into a string using ‘ ‘ (empty string). 




function func() {
    let a = [1, 2, 3, 4, 5, 6];
    console.log(a.join(''));
}
func();

Output
123456

We have a complete list of Javascript Array methods, to check those please go through this Javascript Array Complete reference article.

Supported Browsers: The browsers supported by JavaScript Array isArray() method are listed below:

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript


Article Tags :