Creating a 2d array of objects in javascript - Javascript Array Operation

Javascript examples for Array Operation:Array of Object

Description

Creating a 2d array of objects in javascript

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {/*from  w  ww  .  j av a 2s.  c om*/
var Coords = function(x, y) {
    return {
        "x" : x,
        "y" : y
    };
};
var myArray = [];
for (var i = 0, l = 10; i < l; i++) {
    myArray[i] = [];
    for (var j = 0, l2 = 10; j < l2; j++) {
        myArray[i][j] = Coords(i, j);
    }
}
console.log(myArray);
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials