To convert a list (array) to a string in Javascript, you can use one of two methods: join
or toString
.
The join
method takes an argument which specifies the separator to use between each element of the list when converting it to a string. Here's an example:
index.tsx142 chars4 lines
In this example, we used ,
as our separator to create a string from the myArray
list.
The other method to convert a list to a string is toString
, which simply concatenates all of the list elements into a string separated by commas.
index.tsx140 chars4 lines
Here, again, we get the same output as before. However, note that there are no spaces between elements in the toString
method's output.
gistlibby LogSnag