Multi-dimensional arrays (Definition)

Useful techniques for manipulating matrices for math problems.

Multi-dimensional arrays are not supported directly in JavaScript but you can construct them with arrays of arrays.

An array can refer to another array with one of its elements. This means you can build multi-dimensional arrays, which are useful for working out 3D transformations. You probably wouldn't implement a renderer or 3D modeller in JavaScript. However, you might have a Java applet that takes rotation values or perhaps a 3D viewing plug in of some sort that does the hard work.


Example code:

   // An example shamelessly stolen from Wrox Instant JavaSscript
   // Create a 2x2 array and store an identity matrix in it.
   var matrix = new Array(2);
   matrix[0] = new Array(2);
   matrix[1] = new Array(2);
   matrix[0][0] = 1;
   matrix[1][0] = 0;
   matrix[0][1] = 0;
   matrix[1][1] = 1;

See also:Array index delimiter ([ ]), Copying objects


Wrox Instant JavaScript - page - 16