| Viewed 69 times

How to convert Arrays to Strings in JavaScript


How to convert Arrays to Strings in JavaScript by specifying the separator like [1,2,3,4,5] => "1,2,3,4,5"

1 Answer
Mohammad Qandeel
Answered
12

Converting Arrays to Strings can be done by the following ways:

  • Using The JavaScript method toString()  it will convert an array to a string of (comma separated) array values.

example

var number = ["1", "2", "3", "4"];
console.log(number.toString());  //1,2,3,4
  • Using the JavaScript method join()  it will converts all array elements into a string.

example

var number = ["1", "2", "3", "4"];
console.log(number.join(",")); // 1,2,3,4


Related Questions