Is there a way to efficiently create two 2-D arrays, where each element of the array is an object with unique properties? These arrays are of different sizes and each cell has different properties.
var gridcell = [];
var regionalcell = [];
I have managed to create these arrays using the code below, but I feel that it could be more efficient. Any help would be greatly appreciated!
The values of "w, h, r, c" vary in both functions.
function createCellArray(w, h,r,c)
{
for (j = 0; j < r; j++)
{
gridcell[j] = [];
for (i = 0; i < c; i++)
{
gridcell[j][i] =
{
"x1": w * i,
"y1": h * j,
"x2": w * (i + 1),
"cell_color": null,
"y2": h * (j + 1),
"name": (i + 1 * (j * 10)) + 1
}
}
}
}
function createRegionalCellArray(w, h, r, c) {
for (j = 0; j < r; j++) {
regional[j] = [];
for (i = 0; i < c; i++) {
regional[j][i] =
{
"x1": w * i,
"y1": h * j,
"x2": w * (i + 1),
"cell_color": null,
"y2": h * (j + 1),
"name": (i + 1 * (j * 10)) + 1
}
}
}
}