for (var tower in towers) { // ...} gives you the structure's index within the tower's array. Try something like this: for (var id in towers) { var tower = towers[id]; // ...}