Pushing to an Array within a jQuery each loop
<p>I'm using jQuery to parse an XML file, and I'm trying to push each element in the XML file to an array using a jQuery .each loop. Strangely, if I alert the value of the array within the loop it comes out as it should, but if I try to alert a value in the array after the loop has finished it results in "undefined". </p>

<p>Is there something strange that happens when you push values to an array within this kind of a loop?<br />
<br />
<br />
Here is the Javascript:</p>

<pre><code>var splashArray = new Array();

// Load the Splash XML file and assign each image within to an array
$.get('splash.xml', function(xml) {
 $('image', xml).each(function (i) {
  splashArray.push($(this).attr("src"));
 });
});

alert(splashArray[1]); // Results in undefined
</code></pre>

<p><br />
<br />
Here is the XML:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;site&gt;  
 &lt;image src="splash1.jpg" /&gt;
 &lt;image src="splash2.jpg" /&gt;
 &lt;image src="splash3.jpg" /&gt;
 &lt;image src="splash4.jpg" /&gt;
 &lt;image src="splash5.jpg" /&gt;
 &lt;image src="splash6.png" /&gt;
&lt;/site&gt;
</code></pre>
