How to create a two dimensional array in JavaScript?

JavascriptWeb DevelopmentFront End Technology

A two-dimensional array has more than one dimension, such as myarray[0][0] for element one, myarray[0][1] for element two, etc. To create a two-dimensional array in JavaScript, you can try to run the following code −

Example

Live Demo

<html>    
   <body>              
      <script>  
         var myarray=new Array(3);        
         for (i=0; i <3; i++)          
         myarray[i]=new Array(3)                
         myarray[0][0]="One"        
         myarray[0][1]="Two"        
         myarray[0][2]="Three"        
         myarray[1][0]="Four"        
         myarray[1][1]="Five"        
         myarray[1][2]="Six"        
         myarray[2][0]="Seven"        
         myarray[2][1]="Eight"        
         myarray[2][2]="Nine"  
         document.write(myarray[2][0]);      
      </script>          
   </body>
</html>

Output

Seven
raja
Published on 18-Feb-2018 06:28:32
Advertisements