Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

2d array JS

<script>
  
// Create one dimensional array
var gfg = new Array(3);
  
// Loop to create 2D array using 1D array
document.write("Creating 2D array <br>");
for (var i = 0; i < gfg.length; i++) {
    gfg[i] = [];
}
var h = 0;
var s = "GeeksforGeeks";
  
// Loop to initialize 2D array elements.
for (var i = 0; i < 3; i++) {
    for (var j = 0; j < 3; j++) {
  
        gfg[i][j] = s[h++];
    }
}
  
// Loop to display the elements of 2D array.
for (var i = 0; i < 3; i++) {
    for (var j = 0; j < 3; j++)
  
    {
        document.write(gfg[i][j] + " ");
    }
    document.write("<br>");
}
  
</script>
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #array #JS
ADD COMMENT
Topic
Name
1+1 =