Skip to content

Easy way to turn JavaScript array into comma-separated list?

I have a one-dimensional array of strings in JavaScript that I’d like to turn into a comma-separated list. Is there a simple way in garden-variety JavaScript (or jQuery) to turn that into a comma-separated list? (I know how to iterate through the array and build the string myself by concatenation if that’s the only way.)


The Array.prototype.join() method:

var arr = ["Zero", "One", "Two"];

document.write(arr.join(", "));