Reputation: 314
i have a list like this
const list = ["joe", "stack overflow", "gitlab", "hello React!!!"]
and i want to put this list in a text field separated by end line "\n"
i tried getting the values from the array like this
const values = Array.of(list).join("\n")
but i get the value separated by comma instead of a end line,is there another way i can do this.
Upvotes: 0
Views: 174
Reputation: 46
This does it for me.
const list = ["joe", "stack overflow", "gitlab", "hello React!!!"]
let values = list.join("\n");
console.log(values);
// result
joe
stack overflow
gitlab
hello React!!!
Upvotes: 1
Reputation: 55613
Array.of([1,2,3])
results in [ [1,2,3] ]
- an array with a single element at index 0 which happens to be your array.
As others have pointed out, just do [1,2,3].join("\n")
. But this answer tells you why.
Upvotes: 3
Reputation: 429
Try without 'Array.of'
let list = ["joe", "stack overflow", "gitlab", "hello React!!!"]
const values = list.join("\n")
console.log(values);
Upvotes: 1
Reputation: 13775
["joe", "stack overflow", "gitlab", "hello React!!!"].join("\n")
works for me.
Upvotes: 2