I have a function that consists of a for a loop. Loop runs for a certain time and after that returns a value. my only aim is to return the value, once the loop runs entirely. I tried with Promise and Async-Await but none of them work for me.
Async Function
async function getTotalQuestion(tag, question) {
var output = [];
for (let i = 0; i < question; i++) {
getOne(tag).then((data) => {
output.push(data);
})
.catch((err) => {
console.log(err);
})
}
return output;
}
calling of the async function
getTotalQuestion('eco', 9).then((data) => {
question = data; //here data is coming as undefined
})
.catch((err) => {
console.log(err)
})