Code : Tout sélectionner
const customers = {};
orders.forEach(async (order) => {
const response = await fetch(`/api/customers/${order.customerId}`);
customers[order.customerId] = await response.json();
});
renderOrders(orders, customers);
Code : Tout sélectionner
const customers = {};
orders.forEach(async (order) => {
const response = await fetch(`/api/customers/${order.customerId}`);
customers[order.customerId] = await response.json();
});
renderOrders(orders, customers);Code : Tout sélectionner
const customers = {};
await Promise.all(
orders.map(async (order) => {
const response = await fetch(`/api/customers/${order.customerId}`);
customers[order.customerId] = await response.json();
})
);
renderOrders(orders, customers);
// Promise.all() attend que toutes les promesses soient résolues avant de continuer, contrairement à forEach().