Hey everyone, I have a unique challenge that requires your help. So, I'm working with an array of items and I need to make an Axios post for each item in the array. The catch is that each item relies on data returned from the previous one, so they must be executed synchronously. Here's where it gets tricky - I don't actually know how many items will be in the array. If I had that information, I could handle it like this:
let my_array = [34, 44, 72];
axios.post(
'url-to-get-data',
{
post_data_1: my_array[0]
}
).then(res => {
axios.post(
'url-to-get-data',
{
post_data_1: my_array[1],
post_data_2: res.data
}
).then(res => {
//Third axios post.....
}
).catch();
}
).catch();
If you have any ideas or suggestions on how I can tackle this issue effectively, please share them!