• JavaScript Video Tutorials

JavaScript - Array join() Method



Description

Javascript array join() method joins all the elements of an array into a string.

Syntax

Its syntax is as follows −

array.join(separator);

Parameter Details

separator − Specifies a string to separate each element of the array. If omitted, the array elements are separated with a comma.

Return Value

Returns a string after joining all the array elements.

Example

Try the following example.

<html>
   <head>
      <title>JavaScript Array join Method</title>
   </head>
   
   <body>   
      <script type = "text/javascript">
         var arr = new Array("First","Second","Third");
         
         var str = arr.join();
         document.write("str : " + str ); 
         
         var str = arr.join(", ");
         document.write("<br />str : " + str ); 
         
         var str = arr.join(" + ");
         document.write("<br />str : " + str ); 
      </script>      
   </body>
</html>

Output

str : First,Second,Third
str : First, Second, Third
str : First + Second + Third  
javascript_arrays_object.htm
Advertisements