Computer >> Computer tutorials >  >> Programming >> Javascript

How to convert an array into JavaScript string?


To convert an array into JavaScript string, use the toString() method. JavaScript array toString() method returns a string representing the source code of the specified array and its elements.

Example

You can try to run the following code to convert an array into a string −

<html>
   <head>
      <title>JavaScript Array toString Method</title>
   </head>
   <body>
      <script>
         var arr = new Array("time", "money", "work");
         var str = arr.toString();
         document.write("Returned string is : " + str );
      </script>
   </body>
</html>

Output

Returned string is : time,money,work