Open In App

JavaScript Array join() Method

Improve
Improve
Like Article
Like
Save
Share
Report

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

Array join() Method Syntax

array.join(separator);

Parameters

This method accepts a single parameter as mentioned above and described below:

  • separator: It is Optional i.e, it can be either used as a parameter or not. Its default value is a comma(, ).

Array join() Method Example

In this example, the function join() joins together the elements of the array into a string using ‘|’.

JavaScript




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


Output

1|2|3|4|5|6



Array join() Method Example:

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

Javascript




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


Output

1,2,3,4,5,6



Array join() Method Example

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

Javascript




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


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:



Last Updated : 05 Mar, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads