Function forMap

  • Creates an array of values by running each index of the array through a callback function to initialize its value.

    Type Parameters

    • T

    Parameters

    • size: number

      The length of the array to create.

    • cb: ((index: number) => T)

      The function to initialize each element.

        • (index: number): T
        • Parameters

          • index: number

          Returns T

    Returns T[]

    The created array.

    Example

    Basic usage

    forMap(3, (idx) => idx) // [0, 1, 2]

    forMap(3, (idx) => idx * 2) // [0, 2, 4]

    forMap(2, () => 'foo') // ['foo', 'foo']

Generated using TypeDoc