There are two functions that return string representations of an array:join()
and toString()
.
Both functions return a string containing the elements of the array delimited by commas.
Here are some examples:
let names = ["David", "Cynthia", "Raymond", "Clayton", "Mike", "Jennifer"]; let namestr = names.join(); console.log(namestr); // David,Cynthia,Raymond,Clayton,Mike,Jennifer namestr = names.toString(); //from w w w. ja v a 2 s.co m console.log(namestr); // David,Cynthia,Raymond,Clayton,Mike,Jennifer