Using Async / Await with the Array Reduce Method API (ok)
D:\Tiah\working\MARUNO-21\test.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.11.7/dayjs.min.js"></script>
</head>
<body>
<script>
const fetchJobs = async () => {
const searhs = ['quasi'];
return await searhs.reduce(async (jobsAccumulator, searh) => {
const jobPostingsCall = await fetch(`https://jsonplaceholder.typicode.com/posts?q=${searh}`);
const jobPostings = await jobPostingsCall.json();
jobsAccumulator.push({
searh,
jobPostings,
});
return jobsAccumulator;
}, []);
}
fetchJobs().then(function(job){
console.log(job);
})
</script>
</body>
</html>How to use Promises with reduce and how to choose between serial and parallel processing
The reduce function
reduce functionAsynchronous reduce
reduceTiming
await memo last
await memo lastawait memo first
await memo firstWhen parallelism matters
Conclusion
PreviousSequentially Resolve Promises Works, Giải quyết tuần tự các lời hứa hoạt động (ok)NextFlatten an array of arrays,merge, làm phẳng một mảng các mảng (ok)
Last updated



