Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
7
rated 0 times [  13] [ 6]  / answers: 1 / hits: 30420  / 14 Years ago, mon, february 28, 2011, 12:00:00

How do I output array elements in a textarea, placing each element on its own line?





var your_array = [ Alice, Bob, Eve ];

<textarea id=your_textarea></textarea>




More From » arrays

 Answers
-9

An array has a method to glue all elements together, Array.join. Without an argument, it would use a comma (,) as glue. To put every element on a new line, use the newline character (n).





var your_array = [ Alice, Bob, Eve ];
var textarea = document.getElementById(your_textarea);
textarea.value = your_array.join(n);

<textarea id=your_textarea></textarea>





Example on JSFiddle


[#93538] Saturday, February 26, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marint

Total Points: 550
Total Questions: 105
Total Answers: 124

Location: Zambia
Member since Sat, Oct 31, 2020
4 Years ago
;