access data from ajax function in another function : <p>My MWE data.js looks like this:</p>

<pre><code>var data = [];
function initdata(){
    $.ajax({
        ...
        success: function(data){
            data.push("test");
        },
        ...
    });
}
$(document).ready(function(){
    initdata();
    console.log(data.length);
    console.log(data[0]);
}
</code></pre>

<p>But the console says, <code>data.length</code> is <code>0</code> and <code>data[0]</code> is <code>undefined</code>. How can I access data from an ajax function in another function?</p>
