The Wayback Machine - https://web.archive.org/web/20230512160213/https://www.geeksforgeeks.org/javascript-array-join-method/
Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

JavaScript Array join() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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(, ).

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(, ).

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

JavaScript




function func() {
    var 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.

Javascript




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

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).

Javascript




var 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: The browsers supported by JavaScript Array join() method are listed below:

  • Google Chrome 1.0 and above
  • Microsoft Edge 12 and above
  • Mozilla Firefox 1.0
  • Safari 1 and above
  • Opera 4 and above

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.


My Personal Notes arrow_drop_up
Last Updated : 20 Jan, 2023
Like Article
Save Article
Similar Reads
Related Tutorials