How do you create a multi dimensional array in Javascript using a for loop ?
4 Answers
var test = [];
for(var i = 0; i < 100; i++){
test.push([i, "lol"]);
}
1 Comment
Almir Campos
Simple and works fine.
var sDataArray = MultiDimensionalArray(2, 2);
function MultiDimensionalArray(iRows, iCols) {
var i;
var j;
var table = new Array(iRows);
for (i = 0; i < iRows; i++) {
table[i] = new Array(iCols);
for (j = 0; j < iCols; j++) {
table[i][j] = "";
}
}
return (table);
}
1 Comment
Anderson Green
It looks like this function won't work when initializing arrays with more than 2 dimensions.