title: global variable says undefined - js
body: <p>i'm trying to get some data and store them in an array. when i do this, that works fine and shows the result in $.each inside $.getJSON but outside of that, says array elements are undefined. also when i log length of array inside of $.each , it says 0. i even changed array name but no change. why this behaves like that?
  Thanks!</p>
  
  <pre><code>var topping  = [];
  $.getJSON(getUrlPizza, function(result){
              keepGetData = result;
              var j,k =0;
              $.each(keepGetData, function(i,field){
                  getUrlTopping = urlTopping + "/" + keepGetData[i].id;
                  $.getJSON(getUrlTopping, function(resultT){
                      topp = resultT;
                      $.each(topp, function(t,fieldT){
                          topping[j] = topp[t];
                          console.log(topping[j]); //it shows data
                          console.log(topping.length); // says 0
                          j++;
  
                      });
                  });
  </code></pre>