var arr = new Array("John Doe", 24, "December 17th", 57.2);
// Without argument, concatenates elements into comma-separated string:
alert( arr.join() );
In fact, since JavaScript automatically converts to string anything sent to an alert(), using this method here does no good. Without argument, join() does the same as the toString() method: var arr = new Array("John Doe", 24, "December 17th", 57.2);
alert( arr.toString() ); // Exactly the same as above
Tip: for strings, use the concat() method, or the concatenation operator (plus sign for strings).
var arr = new Array("John Doe", 24, "December 17th", 57.2);
alert( arr.join("\n") ); // One element per line
Tip - manually prepend and append the separator to symmetrically surround the output string: document.write( "#" + arr.join("#") + "#" );
$arr = array('John Doe', 24, 'December 17th', 57.2);
// Print each element, preceded by an HTML line break tag:
echo implode( '<br>', $arr );
Sister / opposite method: split() takes a string to separate another one into an array of strings.