开发者

How do I put an array in a textarea, putting each element on its own line?

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>


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


try to use this

var a = [1, 2, 3, 4];
var msg = a.join("\n");
var area = document.getElementById("textArea");
area.value= msg;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜