Separating javascript elements array.toString ()

Is there a way to separate array.toString() with a semicolon rather than commas?

+4
source share
5 answers

Try using the join method in the array - array.join(";")

+6
source

Check out join () . It takes an argument for the delimiter.

 alert(myArray.join(';')); 
+8
source
 array.toString().replace(/,/g,';'); array.join(';'); 
+1
source
 var arrayAsString = array.toString(); var whatYouWant = arrayAsString.replace(/,/g, ';'); 
0
source

Although the default separator for the join () method is a comma (','), you can also use other separators. Refer to the JavaScript Array Object: join () Method tutorial .

0
source

All Articles