JSFiddle - React, Tailwind, and code Playground
by Abdul Ahmad
JavaScript
function getPromise() {
return new Promise((res) => {
setTimeout(() => res('resolved'), 2000);
});
}
const ar = [1, 2, 3, 4, 5];
async function reduceStuff() {
await ar.reduce(async (acc, i) => {
console.log('reducer');
const res = await getPromise();
console.log('res', res);
console.log('acc', acc);
console.log('i', i);
acc[i] = i;
return acc;
}, {});
}
reduceStuff();