How to represent the source code of an object with JavaScript Arrays?


JavaScript array toSource() method returns a string representing the source code of the array. This method is supported by Mozilla.

Example

You can try to run the following code to learn how to represent the source code of an object with JavaScript Arrays −

<html>
   <head>
      <title>JavaScript Array toSource Method</title>
   </head>
   <body>
      <script>
         var arr = new Array("football", "baseball", "volleyball", "cricket");
       
         var str = arr.toSource();
         document.write("Returned string is : " + str );
      </script>
   </body>
</html>

Updated on: 23-Jun-2020

141 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements