let currComp = this;
let projects = []
let dataArr = []
async function getData() {
let getProject =
await axios.get('url', {
auth: {
username: 'username',
password: 'pw'
}
})
let projects = await getProject.data.value;
let arr = []
let KPIs = []
projects.map(project => {
let item = () => axios.get(`url`, {
auth: {
username: 'username',
password: 'pw'
}
})
arr.push(item)
console.log('arr', arr)
})
let results = await axios.all(arr)
results.map(result => {
result().then(function(v) {
KPIs.push(v.data.value)
})
})
}
getData();
What I am trying to do is:
get an axios call to fetch the name of the projects.
Use those fetched names to call multiple axios calls. This is supposed to give me some data from that project.
results = await axios.all(arr)
contains functions that gives me the responses to the API call.The responses gets pushed in the the array
KPIs
.When I try to
console.log('KPIs', KPIs)
at the end, it gives me
which seems to be an empty array, but when I open it,
it actually has the value that I want.
The problem is, when I try to use this array in my code, it only gives me the first item of the array.
I tried to search this issue online, and it only told me that the value is arriving late.
I want to use the full array with the full result.
How can I fix it?