Javascript Array - join() Method

Tutorialsrack 09/10/2022 Jquery Javascript

In this article, you will learn about the javascript Array built-in method Array.prototype.join(). How does this method work in javascript? 


This Array.prototype.join() method joins the elements of an array and returns a new string separated by commas or a specified separator string. If the length of the array is 0, then it will return the empty string.


This method takes 1 parameter as given below:

  • separator(Optional): The separator to be used. The default separator is a comma (,).

The join() method does not change the original array.

Here are some examples of Array.prototype.join() method:

//Here some examples of Array.join() Method

const arr = ['Java', 'C#', 'Python', 'SQL Server'];
// Output => "Java,C#,Python,SQL Server"

console.log(arr.join(', '));  
// Output => "Java, C#, Python, SQL Server"

console.log(arr.join(' + ')); 
// Output => "Java + C# + Python + SQL Server"

// Output => "JavaC#PythonSQL Server"

//Using join() on sparse arrays
const arr1 = ['Java', , 'C#', 'Python', undefined, 'SQL Server', null];
// Output => "Java,,C#,Python,,SQL Server,"

I hope this article will help you to understand the javascript Array built-in method Array.prototype.join()

Share your valuable feedback, please post your comment at the bottom of this article. Thank you!

Related Posts


Recent Posts