Given the following code
class SomeClass {
async someFunc() {
const urlParameters = [0, 1, 2];
const batchAjaxResult = await urlParameters.map((parameter) => {
const result = await $.get(`someUrl/${parameter}`);
return {
parameter,
result
}
});
console.log(batchAjaxResult);
}
}
JavaScript will return an Array of resolved Promises instead of the actual Promises result.
This is probably due to Array.map()
not being implemented as a Promise.
Is there a Promise-based version of Array.map
?
This is question differs from How to return the response from an asynchronous call, because it's about How to return batched responses wrapped inside Array.map
.