I have this code but I am unable to understand why when I print 'globalData' first it prints all values fine but later when I print it again it print just an empty array? I'm new to JavaScript and jQuery.
<script>
  var globalData = [];
  $( document ).ready(function() {
    $.get( "http://....", function( data ) {
      globalData.push(data[i]);
      .
      .
      .
    });
  console.log(globalData);  //["fg", "wedsd", "hjkyu"]
  });
console.log(globalData);    //[]
</script>
 
     
    