|
| HOW TO JOIN ARRAY ELEMENTS INTO A CONCATENATED STRING USING Array.join() METHOD IN JAVASCRIPT
All individual elements can be joined together into a concatenated string. The Array.join() method is used for this purpose in javascript.
The general format is:
Array.join(optional argument);
Where Array is the declared array and optional argument is any separator you specified. If no optional argument is specified, then a comma is used as separator between elements by default.
Example 1:
var fig= new Array("Pat", "Rick", "Mike");
var str=fig.join();
alert(str); // displays Pat, Rick, Mike
Example 2:
var fig= new Array("Pat", "Rick", "Mike");
var str=fig.join(" ");
alert(str); // displays Pat Rick Mike
Now Read:
|
|