title: Can't access global variable in jQuery $.get within function
body: <p>Below is some code I'm having trouble with.  Basically, I'm defining an empty array as a global variable (var playlist = []) and then trying to add elements to it within a jQuery $.get call.  From what I've read on the internet, I should be able to do this!  The following code gives the error: "Cannot call method 'play' of undefined".  playlist[0] does get set within the function, alerting playlist[0] within the $.get call gives the expected result, but it doesn't persist outside the function.</p>
  
  <pre><code>var playlist = [];
  function playArtist(artist){
    $.get('media/songs/' + artist,
      function(data){
        for (var i in data){
          playlist[i] = setSong(data[i].Resource.name,'track' + data[i].Media.id,i + 1);
        }
      $('#track-total').text(parseInt(playlist.length));
      },'json'
    );
    playlist[0].play();
  }
  </code></pre>
  
  <p>Can anyone help?</p>
  
  <p>Thanks!</p>