Easy way to turn JavaScript array into comma-separated list?
The Array.prototype.join() method:
var arr = ["Zero", "One", "Two"];
document.write(arr.join(", "));
Actually, the toString()
implementation does a join with commas by default:
var arr = [ 42, 55 ];
var str1 = arr.toString(); // Gives you "42,55"
var str2 = String(arr); // Ditto
I don't know if this is mandated by the JS spec but this is what most pretty much all browsers seem to be doing.