rickard rickard - 1 year ago 91
Javascript Question

Javascript string array to multiple strings separated by a comma

How can i convert a string array to output a single string, separated by a comma.


["Red", "Blue", "Green"]

To this
"Red", "Blue", "Green"

I am NOT looking for a comma-separated list of strings.

Answer Source

Use join and pre-/post-fix a couple of extra quotes.

var str = '"' + arr.join('", "') + '"'; // "Red", "Blue", "Green"


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download