Is it possible to interpolate values inside a for loop? I'm using axios and I want that, when it finishes a cycle, it gets to the next json file taking the next value of an array; These are my attempts (not working)
my first try was:
const axios = require('axios')
const array = [foo, bar, baz];
(async()=>{
for(i=0;i<array.length;i++){
const res = await axios.get(`https://blabla/${array[i]}.json`)
// actions
}
})()
but in this way axios makes requests interpolating only the last element of the array (in this case "baz"), while I want that it makes the first request with "foo"and then, when it has completed all the actions, it makes the second request to "bar" and so on up to "baz"
my second try was:
const axios = require('axios')
const array = [foo, bar, baz];
array.forEach(async function(item){
const res = await axios.get(`https://blabla/${item}.json`)
//actions
})
but with this code I get the error "TypeError: Cannot set property 'res' of undefined
"
what can I do?