Problem:
For a student, I would like to fetch latest marks. It's possible that they have some provisional and some accepted marks. Provisional can be edited whereas accepted can't be. First I store by default latestResult in the variable this can either be provisional or accepted. Next, I am trying to run a search for all the results to check the latest accepted. Finally, I would like to know at which index of i does the accepted result exist. However, when I do console.log in .done then value of i always comes as -1 and when I console.log outside the for loop then it comes as blank.
I am looking for any suggestions through which it is possible to access the value of instance i from .done, outside the for loop.
Code
var accepted = 0;
for (var i = res.length-1; i >= 0; i--){
    connectionResult = res[i];
    //latest result
    latestResult = res[res.length-1];
    
    var idNew =  connectionResult.id;
    var filterNew = ['result', 'is', idNew];
    var recordNew = 'acceptedresult';
    
    getData({
        type: recordNew,
        filter: filterNew,
        fields: [
            'id'
        ]
    }).done(function (items) {
        if (items.length > 0) {
            accepted = 1;
            break; //if accepted is one then stop getData 
        }
    });
} //end for
if(accepted == 0){
    var editResultConfirm = confirm("Would you like to edit the Result ?");
    if (editResultConfirm == true) {
        window.open(editResultUrl,'_blank');
    }
}else{
    alert("You have an accepted result");
    window.open(finalResultUrl,'_blank');
}
 
     
    