How Do I return a javascript variable from a function that contains a $.get() request
<p>I've tried Googling this but could not reslove it. It may seem like a really simple issue to others but I'm baffled by it. I have the below code in which I get undefined for the first alert but I still get the correct values in the 2nd alert. BUT if I comment out the first alert (just the line with alert) then the 2nd alert output becomes undefined. Can any one explain why this is and how I may output the 2nd alert correctly without the first one, any Help is greatly appreciated.</p>

<pre><code>function getDetails(ID){
        var qArray = [];
        $.get('get_Question', {"Id":ID}, function(){})
        .success(function(data){
            var json = $.parseJSON(data);
            qArray.push(json.value1);
            qArray.push(json.value2);

        });
        //First Alert
        alert("-&gt; "+qArray[0]);
        return qArray;
     }
</code></pre>

<p>This is the 2nd alert which calls the above method:</p>

<pre><code>var myArray = getDetails(4);
alert("myArray [0]: "+myArray[0]);
</code></pre>
