Documentation
    Preparing search index...
    • Filters an array by applying an asynchronous predicate function to each element.

      Elements are processed sequentially, ensuring order is maintained. The predicate function receives the element, index, and the full array as parameters.

      Type Parameters

      • Input

        The type of elements in the input array

      Parameters

      • elements: readonly Input[]

        The readonly array to filter

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

        The asynchronous predicate function to test each element

      Returns Promise<Input[]>

      A Promise resolving to the filtered array

        const users = [
      { id: 1, name: 'Alice', active: true },
      { id: 2, name: 'Bob', active: false },
      { id: 3, name: 'Charlie', active: true }
      ];

      const activeUsers = await ArrayUtil.asyncFilter(users,
      async (user) => {
      // Async validation logic (e.g., API call)
      await new Promise(resolve => setTimeout(resolve, 100));
      return user.active;
      }
      );
      console.log(activeUsers); // [{ id: 1, name: 'Alice', active: true }, { id: 3, name: 'Charlie', active: true }]