I have this function that returns a list, but the list stays empty even after I add items to the list in the forEach. So I tried using Promises, but I need a little help. Right now the result is "undefined". How do I return the result list after the forEach loop is done?
async function return_list() {
var result = [];
var list_of_skus = [...];
var promise = new Promise(() => {
list_of_skus.forEach((number) => {
api.get(...)
//api request
result.push(api_data)
});
});
promise.then({
return result;
})
}
edit: i changed the code a bit: In the forEach loop im using an api request to get some data, and then add an item the result list