lundi 13 août 2018

Getting an empty array out of function when using callback

I'm trying to access some arrays outside of the function but initially it was just an empty array. So I tried using callback in the function but that didn't change anything.

function liveGames(callback){

  instance.numGames(function(error, result) {
    for(var i = 0; i<result; i++){
      instance.getName(i, function(error, result2) {
        if ((!result2[1]) || (result2[0]==="")) return;
        var newOption = document.createElement("option");
        newOption.text = (result2[0] + " (" + result2[2]*0.000000000000000001);
        newOption.value = result2[7];
        document.getElementById("slct1").add(newOption);
        optionArrayCon.push(result2);
        betArray = optionArrayCon;
        callback && callback();
        console.log(optionArrayCon);
        console.log(betArray);
      });
    }
  });

}

console.log(betArray);
var opt2 = [];
var opt = betArray[0];
 opt2.push(opt[0]);
 console.log(opt2);




Aucun commentaire:

Enregistrer un commentaire