I need to run a function for each item of the array... The problem is, for each run (except the first), the response from the previous run is supposed to be one of the parameters... How do I make sure the next iteration of the function isn't executed till the response from the last one is in place?
I am currently doing it as something like this, but no success:
array --> array with n items
callResponse --> array with (n-1) items
callResponse[0] is a required parameter for the function executing for array[1] and so on....
array = [ ........ ]
callResponse = [....empty x (n-1)....]
for (var i in array) {
var body = {
parameter1: array[i],
parameter2: i = 0 ? '' : callResponse[i-1],
}
axios.get('', body).then((response) => { callResponse[i] = response.data.x }
}