How to use Join of JavaScript

In this article we will discuss about how to use the Join() Method in JavaScript.
  • 2170

This is one of the most important method of the JavaScript which joins all the elements of an array in to a string object. This method takes separator as a parameter which specifies the special character like space comma and plus or any other character to separate each and every element of the array.

JavaScript Code:

<html>

<head>

    <title>JavaScript Array join Method</title>

</head>

<body>

    <script type="text/javascript">

 

        var ar = new Array("One", "Two", "Three");

 

        var st = ar.join();

        document.write("str : " + st);

 

        var st = ar.join(", ");

        document.write("<br />str : " + st);

 

        var st = ar.join(" + ");

        document.write("<br />str : " + st);

    </script>

</body>

</html>

Output:
join.jpg

Ask Your Question 

Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.