JavaScript - Array toString() Method


Advertisements


Description

Javascript array toString() method returns a string representing the source code of the specified array and its elements.

Syntax

Its syntax is as follows −

array.toString();

Return Value

Returns a string representing the array.

Example

Try the following example.

<html>
   <head>
      <title>JavaScript Array toString Method</title>
   </head>
   
   <body>
   
      <script type="text/javascript">
         var arr = new Array("orange", "mango", "banana", "sugar");
         
         var str = arr.toString();
         document.write("Returned string is : " + str );
      </script>
      
   </body>
</html>

Output

Returned string is : orange,mango,banana,sugar 

javascript_arrays_object.htm