0

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?

0

4 Answers 4

4

use the array's join() method:

["a", "b", "c"].join("\n")
Sign up to request clarification or add additional context in comments.

Comments

3
myarray.join("\n")

put that as the textarea value

Comments

1

Try with join

text = array.join("");
document.write(text); // or what ever you would do with text 

1 Comment

Won't be on separate lines per SO request
0

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.

2 Comments

Rofl. Good point. So scratch that concern. Would my stated approach be the best way of going about it?
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.