0

for the past six months I have been programming in nothing but OBJ-C and JAVA so I have been very used to being able accessing objects using object loops

In my JS program I am trying to access all of my created mapped objects and loop through them. How can I get a certain index's object (instead of using my mapped object reference). IE

 var g = new game();
 currentGames[23234395]= g

Lets say I have added three games. I need to be able to get the game by index not by the mapped number (which is just a unique id my data base and I need)

   for(var i = 0;i<currentGames.length;i++)
   {
      var g = currentGames[i];
   }

causes an error (obviously)

Is there any other way of accessing an object by index rather than my map?

EDIT:

I would like to know if i can do something like the following

  for(var g in currentGames)
  {


  }

and g hold a reference to my game object at that index.

Dnaso
  • 1,335
  • 4
  • 22
  • 48
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in – Dark Falcon Sep 03 '14 at 16:44
  • I don't expect you need 23234395 times indexing... – Bhojendra Rauniyar Sep 03 '14 at 16:46
  • 1
    Is this a duplicate of [Loop through JavaScript object](http://stackoverflow.com/q/684672/710446)? I'm not sure what you mean by "index" versus "mapped number". – apsillers Sep 03 '14 at 16:48
  • @C-linkNepal I do. I need a reference to the game (as an id). I also need to loop through them periodically to find an open game. Each player is in a sep game they need a game id to reference when I call back to the server – Dnaso Sep 03 '14 at 16:58

0 Answers0