Documentation
    Preparing search index...
    • Executes an asynchronous function for each element in an array sequentially.

      Unlike JavaScript's native forEach, this function processes asynchronous functions sequentially and waits for all operations to complete. It performs sequential processing rather than parallel processing, making it suitable for operations where order matters.

      Type Parameters

      • Input

        The type of elements in the input array

      Parameters

      • elements: readonly Input[]

        The readonly array to process

      • closure: (elem: Input, index: number, array: readonly Input[]) => Promise<any>

        The asynchronous function to execute for each element

      Returns Promise<void>

      A Promise that resolves when all operations complete

        const urls = ['url1', 'url2', 'url3'];

      await ArrayUtil.asyncForEach(urls, async (url, index) => {
      console.log(`Processing ${index}: ${url}`);
      const data = await fetch(url);
      await processData(data);
      console.log(`Completed ${index}: ${url}`);
      });
      console.log('All URLs processed sequentially');