Skip to main content
added 27 characters in body
Source Link

If you need to create 4d Array with index from 0 to 4 in the each cluster just do this code:

function createNDimArray(dimensions) { if (dimensions.length > 0) { var dim = dimensions[0]; var rest = dimensions.slice(1); var newArray = new Array(); for (var i = 0; i < dim; i++) { newArray[i] = createNDimArray(rest); } return newArray; } else { return undefined; } } var MyArray=createNDimArray([5, 5, 5, 5]); //returns a 5x5x5x5 array with index from 0 to 4; MyArray[4][4][4][4]="MyArray 4d MyValue"; alert(MyArray[4][4][4][4]); //if needFor 5 -demension array with this param.: 5x4x3x2x2 -> do this: var MyArray_5d=createNDimArray([5, 4, 3, 2, 2]); MyArray_5d[4][3][2][1][1]="MyArray 5d MyValue"; alert(MyArray_5d[4][3][2][1][1]);

If you need to create 4d Array with index from 0 to 4 in the each cluster just do this code:

function createNDimArray(dimensions) { if (dimensions.length > 0) { var dim = dimensions[0]; var rest = dimensions.slice(1); var newArray = new Array(); for (var i = 0; i < dim; i++) { newArray[i] = createNDimArray(rest); } return newArray; } else { return undefined; } } var MyArray=createNDimArray([5, 5, 5, 5]); //returns a 5x5x5x5 array with index from 0 to 4; MyArray[4][4][4][4]="MyArray 4d MyValue"; alert(MyArray[4][4][4][4]); //if need 5 demension array do this: var MyArray_5d=createNDimArray([5, 4, 3, 2, 2]); MyArray_5d[4][3][2][1][1]="MyArray 5d MyValue"; alert(MyArray_5d[4][3][2][1][1]);

If you need to create 4d Array with index from 0 to 4 in the each cluster just do this code:

function createNDimArray(dimensions) { if (dimensions.length > 0) { var dim = dimensions[0]; var rest = dimensions.slice(1); var newArray = new Array(); for (var i = 0; i < dim; i++) { newArray[i] = createNDimArray(rest); } return newArray; } else { return undefined; } } var MyArray=createNDimArray([5, 5, 5, 5]); //returns a 5x5x5x5 array with index from 0 to 4; MyArray[4][4][4][4]="MyArray 4d MyValue"; alert(MyArray[4][4][4][4]); //For 5-demension array with this param.: 5x4x3x2x2 -> do this: var MyArray_5d=createNDimArray([5, 4, 3, 2, 2]); MyArray_5d[4][3][2][1][1]="MyArray 5d MyValue"; alert(MyArray_5d[4][3][2][1][1]);

Source Link

If you need to create 4d Array with index from 0 to 4 in the each cluster just do this code:

function createNDimArray(dimensions) { if (dimensions.length > 0) { var dim = dimensions[0]; var rest = dimensions.slice(1); var newArray = new Array(); for (var i = 0; i < dim; i++) { newArray[i] = createNDimArray(rest); } return newArray; } else { return undefined; } } var MyArray=createNDimArray([5, 5, 5, 5]); //returns a 5x5x5x5 array with index from 0 to 4; MyArray[4][4][4][4]="MyArray 4d MyValue"; alert(MyArray[4][4][4][4]); //if need 5 demension array do this: var MyArray_5d=createNDimArray([5, 4, 3, 2, 2]); MyArray_5d[4][3][2][1][1]="MyArray 5d MyValue"; alert(MyArray_5d[4][3][2][1][1]);