| Viewed 55 times

How to convert an array to string in JavaScript


How to convert an array to string in JavaScript

1 Answer
Mikdam Qandeel
Answered
0

The toString() is a method that covert your Array to string.

Note: separated by commas.

Example:

var testArray = ["Qandeel","Academy",2019];

console.log(testArray.toString());

Output:

"Qandeel,Academy,2019"

Another way is by using testArray.toLocaleString().

Note: It's different from device to another.

Finally, you can use join() to convert your array to string.

Note: you can separate with whatever you want.

Example:

var testArray = ["Qandeel", "Academy", "2019"];

console.log(testArray.join(" "));
console.log(testArray.join(" | "));
console.log(testArray.join(' - '));

Output:

Qandeel Academy 2019
Qandeel | Academy | 2019
Qandeel - Academy - 2019