@alextheman/utility - v4.3.5
    Preparing search index...

    Function fillArray

    Creates a new array where each element is the result of the provided callback.

    If the callback returns at least one Promise, the entire result will be wrapped in a Promise and resolved with Promise.all. Otherwise, a plain array is returned.

    The return type of the callback (awaited if any items are a Promise) that becomes the type of the array items.

    A function invoked with the current index. May return a value or a Promise.

    The desired length of the resulting array.

    An array of the callback results, or a Promise resolving to one if the callback is async.

    • Creates a new array where each element is the resolved result of the provided asynchronous callback.

      The callback will be invoked once for each index from 0 to length - 1. If no length is provided, a single-element array will be produced.

      Type Parameters

      • ItemType

        The awaited return type of the callback that becomes the type of the array items.

      Parameters

      • callback: (index: number) => Promise<ItemType>

        An asynchronous function invoked with the current index.

      • Optionallength: number

        The desired length of the resulting array.

      Returns Promise<ItemType[]>

      A Promise resolving to an array of the callback results.

    • Creates a new array where each element is the result of the provided synchronous callback.

      The callback will be invoked once for each index from 0 to length - 1. If no length is provided, a single-element array will be produced.

      Type Parameters

      • ItemType

        The return type of the callback that becomes the type of the array items.

      Parameters

      • callback: (index: number) => ItemType

        A synchronous function invoked with the current index.

      • Optionallength: number

        The desired length of the resulting array.

      Returns ItemType[]

      An array of the callback results.