Professor Java
Your Ad Here
When working on my javascript implementation for the determinant of the matrix, I had to create a two-dimensional array. Javascript does not offer one, so I looked online and there are a couple of solutions do this. Javascript doesn't offer a two-dimensional array declaration so you must declare an array then declare an array in one of the elements. For example:

var multiArray= new Array(3);

Note that these "two dimensional arrays have special properties: the rows don't have to be the same size, or the same type for that matter, since they are acting as seperate arrays anyways. multiArray[0] had 4 ints, multiArray[1] had 4 strings, and multiArray[2] had 1 double. These arrays can hold even more arrays (higher dimensions) or even objects.

However, what if you do need a two dimensional array with the columns of the same size, and the same type, just like in java? For example, for a 5x8 array in java, I would use something like:
int[][]cool=new int[5][8].
For javascript, let r=how many rows you want and c=how many columns you want. The code would be:

var multiArray= new Array(r);
for(var i=0;i<multiArray.length;i++){
multiArray[i]=new Array(c);

This would give you the code you need to create a two-dimensional array with r rows and c cols. Then you can access an element in the two-dimensional array simply, like multiArray[1][3].

Comments below, please.
3/13/2012 06:52:23 pm

Javascript it is a protype scripting language which has weaklytyped but has 1st class functions.

9/24/2012 05:55:09 am

Nice info dude


Leave a Reply.
Provided by site.
Your Ad Here