rickard rickard - 1 month ago 11
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.

Convert

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

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


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

Answer

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

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

DEMO

Comments