title: How to select first item in javascript object using javascript?
body: <p>I am quite new to javascript/angular and was pondering whether or not there is an easy way to grab the first item in a javascript object/array. </p>
  
  <p>EDIT: I do have control at this point in time in how I format the array, so perhaps there is a better way to do this using ID as keys?</p>
  
  <p>Lets say I want to match the first item in the array. My thinking is to simply loop through the object checking the ID value.</p>
  
  <p>The js function may look something like this:</p>
  
  <pre><code>app.controller('gamesController',function(){
  
      //Function to load the games
      this.loadGameIntoModal = function(game_id){
  
          for (i=0;i&lt;=length(games);i++){
              if (games[i]['id'] === game_id)
              {
                     this.games = games[i]['id'];
                     //Load the modal
                     $("#game_modal").modal();
                     break;
              }
          }
      }
  });
  </code></pre>
  
  <p>So my question is simply, is there a better way to do this than to use a loop?</p>
  
  <pre><code>var games = [
  
          {
          id   : 1,
          name : 'ABC Games',
          games : [
                  {
                      id   : 1,
                      name : 'ABC 1',
                  },
                  {
                      id   : 2,
                      name : 'ABC 2',
                  } ,
                  {
                      id   : 3,
                      name : 'ABC 3',
                  }
              ]
          },
          {
              id   : 2,
              name : 'XYZ',
              games : [
                  {
                      id   : 4,
                      name : 'XYZ 1',
                  },
                  {
                      id   : 4,
                      name : 'XYZ 2',
                  } ,
                  {
                      id   : 5,
                      name : 'XYZ 3',
                  }
              ]
  
          }
      ];
  </code></pre>