Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

How to create a string by joining the elements of an array in JavaScript ?

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

Given an array containing array elements and here we will join all the array elements to make a single string. To join the array elements we use arr.join() method. This 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) 

Example: In this case, we use an empty separator i.e. array.join(“”) to join the array elements.

HTML




<body style="text-align: center;">
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
  
    <h3>
        How to create a string by joining the<br>
        elements of an array in JavaScript?
    </h3>
  
    <h4>Original Array: ["Welcome", "Geeks", "for", "Geeks"]</h4>
  
    <button onclick="geeks()">Click Here!</button>
  
    <h4 id="result"></h4>
  
    <script>
        function geeks() {
            var str = ["Welcome", "Geeks", "for", "Geeks"];
          
            document.getElementById("result").innerHTML 
                = "Joined String: " + str.join("");
        }
    </script>
</body>

Output:

 

My Personal Notes arrow_drop_up
Last Updated : 09 Dec, 2022
Like Article
Save Article
Similar Reads
Related Tutorials