Sequential Promises

Execute async operations sequentially, ensuring each completes before starting the next.

Code

Boilerplates
const sequential = async (arr, fn) => {
  const results = [];
  for (const item of arr) {
    results.push(await fn(item));
  }
  return results;
};

const results = await sequential([1,2,3], async x => x * 2);
return results.join(',');
Browser·fetch() may be limited by CORS

More JavaScript Snippets