Tweakr
    Preparing search index...

    Function filterAsync

    • Asynchronously filters an array based on a provided async predicate function.

      Executes all predicate calls in parallel using Promise.all, and returns a new array containing only the elements for which the predicate resolves to true.

      Type Parameters

      • T

        The type of elements in the input array.

      Parameters

      • arr: T[]

        The array to filter.

      • predicate: (item: T, index: number, array: T[]) => Promise<boolean>

        An async function called for each element. Should resolve to true to keep the element.

      Returns Promise<T[]>

      A promise that resolves to a new array containing the filtered elements.

      const isEvenAsync = async (n: number) => n % 2 === 0;
      await filterAsync([1, 2, 3, 4], isEvenAsync);
      // → [2, 4]

      1.0.0