JavaScript array element to string
19,169
Solution 1
You must use the join function on the array:
var teststring = array.join(",");
Solution 2
array.join(",")
Comments
-
cupakob almost 2 years
i have a simple array and i want to generate string which include all the elements of the array, for example:
The array is set as follow:
array[0] = uri0 array[1] = uri1 array[2] = uri2
And the output string must be
teststring = uri0,uri1,uri2
I've tried to make this following way (using for loop):
var teststring = ""; teststring = teststring+array[y]
but in the firebug console i see an error message:
"teststring is not defined"
I don't know, what I'm doing wrong. Can someone give me a hint?