Q:

Creating javascript multi-dimension array (3 dimension) with some rules

I have a problem with my multi-dimensional array syntax in javascript.
So, i want to built 3 dimensional array with this rule :

When the value of the first array 'x' increases [x][y][z], the value of 'y' and 'z' [x][y][z] will be reduced, for example :
the first[0], it has [5][5] number of 2 multidimensional array
the second[1], it has [4][4] number of 2 multidimensional array
the third[2], it has [3][3] number of 2 multidimensional array
the fourth[3], , it has [2][2] number of 2 multidimensional array
So, this is my syntax :

var values = 5;
var temp = 7;
var data = new Array(values);
//looping for buliding 2nd multi-dimensional array
for(var a=0;a<values;a++){
  temp=temp-1;
  data[a] = new Array(temp);
}
//looping for buliding 3rd multi-dimensional array    
temp=7;
for(var a=0;a<values;a++){
  temp=temp-1;
  for(var b=0;b<temp;b++){
    data[a][b] = new Array(temp);    
  }
}

can it solve the problem?
Thanks

A:

You can do this by just having two loops the outer one setting up the first dimension and the inner creating both the second and third dimensions with the same size.
var values = 5;
var temp = 7;
var data = new Array(values);
var a, b;

for(a = 0; a < values; a++ ) {
  temp--;
  data[a] = new Array(temp);
  for(b = 0; b < temp; b++ ) {
    data[a][b] = new Array(temp);
  }
}

