Reputation: 199
document.getElementById("hi2").value = arrayd[i] + document.getElementById("hi2").value + ',';
hi2 is a TEXTAREA
When I fill the textarea with the array I don't know how to add a space after every item in the array.
This is the END Result Im looking for:
Jill
Bob
Tony
Nancy
Upvotes: 1
Views: 84
Reputation: 3337
Try this:
<textarea id="hi2"></textarea>
<script type="text/javascript">
var arrayd = ['Jill', 'Bob', 'Tony', 'Nancy'];
document.getElementById("hi2").value = arrayd.join("\n");
</script>
Upvotes: 0
Reputation: 32598
You can use Array#join
to insert a newline in between each array element
document.getElementById("hi2").value = arrayd.join("\n");
Upvotes: 1