Arrays used in Javascript

<html>
 <head>
  <title>Array example</title>
 </head>
 <body>
  <script type="text/javascript">
  <!--
 var array = new Array(1);
 // Undefined: Array values not defined.
 for (var i = 0; i < array.length; i++) {
   document.write(array[i] + "<br>");
 }
 document.write("<hr>");

 // creating horizantal arrays
 var earth = new Array();
 earth.diameter = "7920 miles";
 earth.distance = "93 million miles";
 earth.year = "365.25 days";
 earth.day = "24 hours";

 document.write(earth.diameter + "<br>" + earth["distance"] + "<br>" + earth["year"] + "<br>" + earth.day + "<br>");

 document.write("<hr>");
 document.write("<h3>Array example initalizing array values</h3>");
 // Creating arrays by assigning literal notations.
 solarSystem = ["a","b","c","d","e"];
 for(var i = 0; i < solarSystem.length; i++)
   document.write(solarSystem[i] + "<br>");


  //-->
  </script>
 </body>
</html>

Comments

Popular Posts