Array.join() (Method)

Concatenate array elements to make a string.

Availability:

ECMAScript edition - 2
JavaScript - 1.1
JScript - 3.0
Internet Explorer - 4.0
Netscape - 3.0
Netscape Enterprise Server - 2.0
Opera - 3.0
Property/method value type:String primitive
JavaScript syntax:-myArray.join(aSeparator)
Argument list:aSeparatorA string to place between array elements as the array is concatenated to form a string.

The result of this method will be a String primitive containing the array elements interposed with separators.

The elements in the array are converted to strings and are concatenated together to form a larger string. Each element has the separator value placed between it and the next element.

If the separator is not specified, then a single comma is used to join the array elements. This means that if you want no separation between the joined items you should pass an empty string as the separator value.

Example code:

   <HTML>

   <HEAD>

   </HEAD>

   <BODY>

   <SCRIPT>

   // Demonstrate array joins

   myString1 = "This is a sentence made of words.";

   document.write("Original input string<BR>")

   document.write(myString1)

   myArray = myString1.split(" ");

   document.write("<BR><BR>String split into an array<BR>")

   displayArrayAsTable(myArray);

   myString2 = myArray.join("+");

   document.write("<BR><BR>Array joined up as a string<BR>")

   document.write(myString2)

   

   // Display an array in a table

   function displayArrayAsTable(anArray)

   {

      myLength = anArray.length;

      document.write("<TABLE BORDER=1>");

      for(myIndex = 0; myIndex < myLength; myIndex++)

      {

         document.write("<TR><TD>");

         document.write(myIndex);

         document.write("</TD><TD>");

         document.write(anArray[myIndex]);

         document.write("</TD></TR>");

      }

      document.write("</TABLE>")

   }

   </SCRIPT>

   </BODY>

   </HTML>

See also:Array.prototype, Cast operator, String concatenate (+), String.split()

insert figure 0011

Cross-references:

ECMA 262 edition 2 - section - 15.4.4.3

ECMA 262 edition 3 - section - 15.4.4.5