The function is intended to loop over an array and POST each value in the array to database. I got error if I use async await function.
Error : Can not use keyword 'await' outside an async function
const myfunction = async () => {
[1,2,3].map((item) => {
const endpoint = "/api/";
await apiService(endpoint, "POST", item)
.then((r) => console.log(r))
});
};
The apiservice function use browser fetch function with stored cookie
This might be duplicate of following question Using async await when mapping over an arrays values, but I did not understand it.
.map()might be an overkill. Can use simpleforloop orfor (item of array) {..}.