Anyone have a function to create 4D arrays (or any number of dimensions for that matter)?
I\'d like to call the function, then after that I can do something like
Very simple function, generate an array with any number of dimensions. Specify length of each dimension and the content which for me is '' usually
function arrayGen(content,dims,dim1Len,dim2Len,dim3Len...) {
var args = arguments;
function loop(array,dim) {
for (var a = 0; a < args[dim + 1]; a++) {
if (dims > dim) {
array[a] = loop([],dim + 1);
} else if (dims == dim) {
array[a] = content;
}
}
return array;
}
var thisArray = [];
thisArray = loop(thisArray,1);
return thisArray;
};
I use this function very often, it saves a lot of time
Quick and dirty:
var arr = [[[[[]]]]];
Check it out http://jsfiddle.net/MJg9Y/
Note: You will still need to initialize each dimension. The above creates the foundation for a 4 dimension array at arr[0]
.