Skip to content

JavaScript array to string with commas | Convert code

  • by

Use the join() method or toString() method to convert an array to a string with commas in JavaScript. And if you want to convert an array of objects into a string, then use the JSON.stringify method:

 arr.join();

You can specify an empty string as an argument to join, if no argument is specified a comma is used.

Example JavaScript array to string with commas

A simple example code join() method returns an array as a string.

<!DOCTYPE html>
<html>
<head>

  <script>

    let arr = ["ABC", "Is", "Popular","Language"];
    let res  = arr.join();

    console.log(res);
    console.log(typeof(res))

  </script>

</head>
</html>

Output:

JavaScript array to string with commas

The method array.toString() actually calls array.join() which results in a string concatenated by commas.

var array = ['a','b','c','d','e','f'];
document.write(array.toString());

Output: “a,b,c,d,e,f”

Do comment if you have any doubts or suggestions on this JS convert array to string code.

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

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading