The join method

The join() method is used to combine the elements of two or more arrays into one string. The elements in the string are separated by a character sent to the method as parameter. A comma is used by default if no parameter is sent.

var Animals = new Array("dogs" , "cats" , "chickens");
var AnimalsString = Animals.join();
document.write(AnimalsString);

If you want the elements in the string to be separate by a separator character (|) then you send it to the join() method as a parameter.

var Animals = new Array("dogs" , "cats" , "chickens");
var AnimalsString = Animals.join("|");
document.write(AnimalsString);

Leave a Reply