lundi 18 mai 2015

Javascript: pushing certain info to Array and getting info out of array

I have a question about the following problem:

I made a board for a game made out of pieces. Each piece has its own x and y coordinates, but also a boolean wether it's a road or not and wether it has a turret on or not.

So this is the Array:

var Array = [""];            
Array.push({
          x: i, 
          y: j,
          road: false,
          tower: null,
          id: "gamezone"+j+i
        });

Now, the Array.push is found in a loop which gives the information: that part works. Now for the question:

How do I edit certain information of each object of the array? For instance, certain pieces do have a road on, so what I did was:

Array.push({road: true});

but that didn't do it. How would I do that?

Second question: If I want to use some information of objects of the array, for example I have to make an if-else with if (Array(road = true)) then ... I don't think that's a correct way to get info out of the array, so please help me there.

If you've any documentation on doing this, mind giving a link as well?

Thanks a bunch!

Aucun commentaire:

Enregistrer un commentaire