I'm building a data structure for storing tile data from isometric maps. I'm currently using a multidimensional array with 3 axis.
var tile = tilesArray[X][Y][Z];
I'm wondering if it would be faster to use a for loop to find data
tilesArray[i] = tileObject
function getTile(x, y, z) {
//loop through the tiles till we find the right one
for (var i = 0; i < tilesArray.length; i += 1) {
//grab the tile
var tile = tilesArray[i];
//check the tile position to see if it is the one requested
if (tile.position[0] = x && tile.position[1] = y && tile.position[2] = z) {
return tile;
}
}
//if the tile is not found and we fall out of the for loop return false
return false;
}
So to recap
var tile = tilesArray[X][Y][Z];
vs
var tile = getTile(x, y, z);