How would you go about putting an array into a textarea, each value on its own line? I thought about converting the array to a string, and the commas into new lines, but what if the value of an array item has a comma?
A:
If you have a comma delimited array that contains values with unescaped commas, you have an insurmountable problem. You need to convert the array into a string with some other sort of delimiter, preferably the linebreaks you want them to be in the end.
jball
2010-02-19 21:52:09
Rofl. Good point. So scratch that concern. Would my stated approach be the best way of going about it?
Matrym
2010-02-19 21:52:46
Some of the other answers have examples of using the array's `join` method with `\n` as the delimiter. That would be a good way to go.
jball
2010-02-19 21:55:38
+1
A:
Try with join
text = array.join("");
document.write(text); // or what ever you would do with text
streetparade
2010-02-19 21:53:51