Wednesday, 12 April 2017

i am pushing elements in array but array remains empty [duplicate]

This question already has an answer here:

The array x is not updating it gets updated inside the find function but outside the scope of Updating block it remains empty

if (req.session.username == sessionobj && req.session.admin) {
          var x=[];
          //aadhar doc fetch

          aadhar.find({username : req.session.username},function(err,respo){
            console.log("one");
            if(err){
              x.push({path : "documents/no.png" , status : "error fetching 
              documents"});
              console.log(x); // display updated array
            }
            else{

              if (respo[0].verified) {
                x.push({path : "documents/"+respo[0].filename , status : 
                "verified"});
                console.log(x); // display updated array
              }
              else{
                x.push({path : "documents/"+respo[0].filename , status : "Not 
                verified"});
                console.log(x); // display updated array
              }
            } 
          });
    console.log(x); //always display empty array
}



via user6332455

No comments:

Post a Comment