I'm a beginner in async await and promises. I read few articles and watch few tutorial videos but I am still not able to understand it completely. So I have a code that I'm working on right now
}).then(function() {
var responseArray = []
[url1,url2,url3,url4].forEach((url)=>{
makeRequest(url)
}).then((response)=>{
responseArray.push(response)
})
return responseArray
})
So as expected the responseArray
is returned empty. I need to make it wait until all the responses from each makerequest(url) is pushed to the responseArray.
This is my attempt
}).then(function() {
var responseArray = []
[url1,url2,url3,url4].forEach((url)=>{
async makeRequest(url)
}).then((response)=>{
await responseArray.push(response)
})
return responseArray
})
Can anyone help me fix this one?