Anjan Dutta

How to convert an Array to a String in JavaScript

How to convert an Array to a String in JavaScript

Created On: 02/10/2021

To convert an array to a string in javascript, we can use the toString() method.

The below code explains how to do the conversion.

var words = ['this', 'is','business'];
var str = words.toString();
console.log(str);
// Output:
// > this,is,business

So, the output of this code will be a string containing all the objects as comma-separated.

To use any other delimiter than a comma, we can use the join() method like below.

var words = ['this', 'is','business'];
var str = words.join(" ");
// Output:
console.log(str);
// > this is business

The toString() method doesn't accept any parameter to use as a delimiter. But the join() method has this feature. So we can use join() to create more formatted strings from an array.