Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Turn Array into String

Status
Not open for further replies.

Greenster

Programmer
Jan 14, 2002
30
0
0
GB
In PHP you can turn an array into a string using implode() is there a similar function is javascript?

Thanx {Greenster}
 
yes and it is called join()

var myWords = ["Here", "is", "how", "it", "works."];
var mySentence = myWords.join(" ");
alert(mySentence)

Hope this helps. Gary Haran
 
Try:

var string = array.join(separator);

or

var string = array.join();

separator is a variable containing whatever delimiter you want to use, or an empty string is used if it is left out.
 
Thanks very much - that has helped me.

Cheers {Greenster}
 
glad it helped.

by the way if you have an array and you alert the array you will get it in a string format seperated by comas.

Try :

var myWords = ["Here", "is", "how", "it", "works."];
alert(myWords)
Gary Haran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top