I'm trying to handle loop with $.get that handle error with adding fail attempt to log.
var fileSuccess= [];
var fileFail= [];
  if (records.length > 0) {
        
    $.each(records, function(i,r){
        fileName= model.getValue(r,"NAME");
        folderName= model.getValue(r,"FOLDER");        
        
        var promise = $.get(url + folderName + "/" + fileName, function() {
            fileSuccess.push(folderName+ "/" + fileName);
            })
        .fail(function() {fileFail.push(fileName);});
        
     });  
    
    console.log(fileSuccess); 
    console.log(fileFail); // it shows array [] but with two objects 0:xxxx, 1:xxxx, length = 2
    console.log(fileFail.length); // it shows 0
      
};
Why fileFail array is losing all data?
