app.get('/upload/:candid', function(req,res){
const candId = req.params.candid
let candidateArray =""
let statusArray = ""
let cand_id = " "
Candidate.find({idno:candId},function(err,foundcandidate){
if (err){
console.log(err)
}else{
for (const [key, value] of Object.entries(foundcandidate)) {
cand_id= `${value._id}`
candidateArray=foundcandidate
}
}
})
Status.find({candidate:cand_id}, function(err, foundattachments){
if (!err){
statusArray = foundattachments
} else if (err){
console.log(err)
}
})
console.log(candidateArray)
how can i assign candudateArray within a function and access it outside that function
Read more here: https://stackoverflow.com/questions/66273314/how-to-declare-variables-that-are-within-functions
Content Attribution
This content was originally published by Teddy Ted at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.