Medium
This question is a daily question and will count towards your daily streak.
In JavaScript, when working with Promises, what is a practical use case for Promise.all?
1async function fetchData(urls) {2 const requests = urls.map((url) => fetch(url).then((res) => res.json()));3 try {4 const results = await Promise.all(requests);5 console.log('All data fetched:', results);6 return results;7 } catch (error) {8 console.error('Error fetching data:', error);9 }10}1112const apiEndpoints = [13 'https://api.example.com/user',14 'https://api.example.com/posts',15 'https://api.example.com/comments',16];1718fetchData(apiEndpoints);