How do I return value of stuff
outside the for loop. I need to make an API call i
amount of times and store the result each time. There is probably a duplicate question somewhere with the answer but I am unable to find it.
function getResponse() {
var stuff = []
for (let i = 0; i < length; i++) {
axios.get(url + i)
.then(res => res.forEach(item => {
stuff.push(item)
}))
}
// How do I return stuff from this function ?
}
console.log(getResponse())
I've tried making this function only do a call and then looping in another function which calls this but I get:
cannot read property then of undefined.