Share on Google+Share on Google+

JavaScript array dimension

Advertisement
In this code we help you to understand array dimension. In this code we use Java Script as scripting language.

JavaScript array dimension

     

In this code we help you to understand array dimension. In this code we use  Java Script as scripting language. The code shows you to make a Two dimension array. The page on loading invoke a function display ( ) that include an array variable used to instantiate an array object with initial size of 3.The for loop run and execute the script till the length  of row, column i.e i,j is less than 3 .The document. write print an array with three rows and columns. Again the for loop run and execute for the element in an array till the length i,j is less than 3.Finally the document. write print the element in a 1st array.

The same procedure is implied to print 2nd array dimension. In this array we print the twice of element in first array using document. write.

Array Dimension.html
<html>
 <head>
  <title>Array Dimension</title>
  
  <script>

 function display() {
 var array = new Array(3);
  
 for(i = 0; i < 3; i++) {
 array[i]new Array(3);
  }

    for(i = 0; i < 3; i++ ) {
 for(j = 0; j < 3; j++) {
 array[i][j]=""+(i+1)+(j+1);
  }
 }
  
 document.write("<h2>Two Dimension Array</h2><hr>");

 document.write("<b>1st Array :</b>");
 document.write("<br><br>&nbsp;&nbsp;&nbsp;&nbsp;");
 for(i = 0; i < 3; i++ ) {
 for(j = 0; j < 3; j++) {
  document.write(" &nbsp;&nbsp;&nbsp;&nbsp;"+array[i][j]);
 }
 document.write("<br>&nbsp;&nbsp;&nbsp;&nbsp;");
  }
  document.write("<br><br>");
  document.write("<b>2*1st Array :</b>");
 
  document.write("<br><br>&nbsp;&nbsp;&nbsp;&nbsp;");
  for(i = 0; i < 3; i++ ) {
  for(j = 0; j < 3; j++) {
 document.write(" &nbsp;&nbsp;&nbsp;&nbsp;");
 document.write(array[i][j]*2);
 }
  document.write("<br>&nbsp;&nbsp;&nbsp;&nbsp;");
 }
  }
  </script>
  </head>
  
  <body onload="display();">
  
  </body>
</html>

Output



Download code

Advertisements

Advertisement

Posted on: November 11, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: JavaScript array dimension  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0