Skip to content

Array to comma separated string JavaScript | Code

  • by

Use toString() method to convert an Array to a comma-separated string in JavaScript. The method array.toString() actually calls array.join() which results in a string concatenated by commas.


Or pass the array as a parameter to the String object – String(arr). The String object will convert the passed-in array to a comma-separated string and return the result.

Array to comma-separated string JavaScript

Simple example code.

<!DOCTYPE html>

    var array = ['a','b','c','d','e','f'];

    const arr = ['one', 'two', 'three'];
    const str = String(arr);
    console.log(typeof str);



Array to comma separated string JavaScript


Or join() method joins all elements of an array into a string. It accepts a separator as an argument, but the default is already a comma ,

str = arr.join([separator = ','])


var array = ['A', 'B', 'C'];
var myVar1 = array.join();      // 'A,B,C'
var myVar2 = array.join(', ');  // 'A, B, C'
var myVar3 = array.join(' + '); // 'A + B + C'
var myVar4 = array.join('');    // 'ABC'

Do comment if you have any doubts or suggestions on this Js Array string topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *