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.
The arrays are not truly multi-dimensional and you must be careful to construct them properly and avoid damaging them inadvertently.
// 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 |
| Prev | Home | Next |
| Multi-byte character | Up | Multi-line comment |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. | ||