Use two-dimensional array to store matrix data : Two Dimensional Array « Data Type « JavaScript DHTML






Use two-dimensional array to store matrix data

  

<html>
  <head>
    <title>Array literal</title>
    <script type="text/javascript" >

var planets = [
    [1, 'K', 'F', 'M', '1:45'],
    [2, 'N', 'G', 'M', '3.8'],
    [3, 'M', 'A', 'W', '8.4'],
    [4, 'F', 'S', 'R', '6.4'],
    [5, 'J', 'C', 'M', '6.6']
    ];
for (var i = 0; i < planets.length; i++)
{
  for (var j = 0; j < planets[i].length; j++)
  {
    document.write('planets[' + i + '][' + j + '] = ' + planets[i][j]);
    document.write('<BR>');
  }
}    
    </script>
  </head>
  <body>
  </body>
</html>

   
    
  








Related examples in the same category

1.Another way to declare the two-dimensional array
2.Use nested for loop to loop through the two-dimension array
3.Sort two dimensional array