• Category

    Create a new array of a specified length and fill it with a given value.

    Time complexity: O(n)

    Space complexity: O(n)

    Type Parameters

    • T

    Parameters

    • value: T

      Value to fill the array with

    • length: number

      The length of the array

    Returns T[]

    The filled array

    Example

    fill('a', 3); // ['a', 'a', 'a']
    

    See

    • mapFill to do the same thing but with a function that generates values
    • repeat to do the same thing but return an iterable

    Array