How to convert JavaScript array into the comma-separated string?

How to convert JavaScript array into the comma-separated string?

In this Javascript tutorial, I am going to let you know how to create comma separated list from an array in Javascript.

In the Javascript, there are many method that converts array into string and sometime you need specified separator while converting array into the string.

The following example will let you know how you can define separator and how many ways you can convert array into the string list.

Array join() method

You can use join method that will join the array elements into the new string. By default array elements are separated with a (",") comma separator.

Syntax:
array.join()

You can also pass the separator in join method to convert array with specified separator.

array.join(", ")
Example
<html>
   <head>
      <title>JavaScript - Convert array into the comma-separated string - Expertphp.in</title>
   </head>

   <body>
      <script>
         var arr = ["Web Developer","Web Designer","Tester"];         
         // with default separator
         document.write(arr.join());
         // with defined separator
         document.write(arr.join("="));
      </script>
   </body>
</html>
Array toString() method

You can also use toString method to convert array into a string. It will return a string, separated by a comma.

Syntax:
array.toString()
Example
<html>
   <head>
      <title>JavaScript - Convert array into the comma-separated string - Expertphp.in</title>
   </head>

   <body>
      <script>
         var arr = ["Web Developer","Web Designer","Tester"];                 
         document.write(arr.toString());
      </script>
   </body>
</html>

Phone: (+91) 8800417876
Noida, 201301
Attention Required! | Cloudflare

Sorry, you have been blocked

You are unable to access ressim.net

Why have I been blocked?

This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.

What can I do to resolve this?

You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page.