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.)
Tell me more
×
Stack Overflow is a question and answer site for
professional and enthusiast programmers. It's 100% free, no registration required.
|
The join function:
|
|||||||||||||||||||||
|
Or (more efficiently): var arr = new Array(3); arr[0] = "Zero"; arr[1] = "One"; arr[2] = "Two"; document.write(arr); // same as document.write(arr.toString()) in this context The toString method of an array when called returns exactly what you need - comma-separated list. |
|||
|
Actually, the
I don't know if this is mandated by the JS spec but this is what |
|||||
|