Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Web
Expertise: Intermediate
Aug 7, 1998

Convert an Array Into a String in JavaScript

If you want to convert an array into a sting, the join method is your best bet. This method takes one parameter and uses it as the separator between each array element as it is added to the string. Although spaces, commas, and dashes are common separators, you can forego a separator completely by specifying an empty string ("") as the parameter. So a command like myarray.join("") will create a string with nothing between the array elements.

 
<HTML>
<HEAD>
<SCRIPT Language="JavaScript">
function joinArray()
{
  var a, b;
  a = new Array(0,1,2,3,4);
  b = a.join("");
  return(b);
}
</SCRIPT>
</HEAD>
<BODY>
The result is 
<SCRIPT Language="JavaScript">document.write(joinArray());
</SCRIPT>
</BODY>
</HTML>
Boris Feldman
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date