async function - await not waiting in for loop

Viewed 25

I'm trying to send info to my api, but await not waiting, I know it doesn't work cause my backend does not support Multiples Active ResultSets

const myArray = [ {name: 'Team1'}, { name: 'Team2'}, { name: 'Team3'}]

    const testPost = async () => {

        for (const team of myArray) {

            await axios({
                    method: 'POST',
                    url: 'https://myapi/api/team',
                    data: {
                        name: team.name,    
                    }
            }).then(() => console.log('Post!')) 
        }
    }
    
    testPost();
0 Answers
Related