How do I get the value returning from console.log (results [4] .geocode) to use when comparing my if?

1
   var init = [iAppLib.getPersonalBits(),
               iAppLib.getGeoCode()                   
               ];
   var codes = false;
    var gcOk = new Array("BRH04700","BRH04600","BRH00200","BRH04500","BRJ01400","BRM00100","BRM00200","BRM09600","BRM04200");


    for(var i = 0; i < gcOk.length; i++){
        if(gcOk[i] == stb){
            codes= true;
        }
    }


  if(codes){
        document.write("</head>");
        document.write("<body background='bg.mpg'>");
        document.write("</body>");
        document.write("</html>");

    }else{
        document.write("</head>");
        document.write("<body background='tv:'>");
        document.write("</body>");
        document.write("</html>");
    };

   Promise.all(init).then(function (results) {
       console.log(results[4].geocode); 

   });

}) ();

    
asked by anonymous 13.12.2017 / 12:56

1 answer

1

If the if you want to create is already in the code you posted, just put all the code (except the init function) inside your Promise's then (). This will cause the code to run as soon as its promise has the result of the init function.

If the if is some other that will go into a later implementation, just use the normal assignment:

Promise.all(init).then(function (results) {
   var meu_resultado = results[4].geocode;
   if(meu_resultado == minha_condicao){
       //Código do seu if
   }
});
    
13.12.2017 / 13:17