How to convert an array into JavaScript string?

JavascriptWeb DevelopmentFront End Technology

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 −

Live Demo

<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
raja
Published on 12-Feb-2018 16:49:04
Advertisements