• Category

    Pads an array with a given value so that the array reaches a given length. The padding is applied from the end (right) of the array.

    Time complexity: O(n)

    Space complexity: O(n)

    Type Parameters

    • T

    Parameters

    • array: T[]

      The array to pad

    • maxLength: number

      The length of array once it has been padded. If this parameter is smaller than array's length, array will not be modified

    • fillValue: T

      The value to pad the array with

    Returns void

    const array = [0, 1, 2];

    padEnd(array, 4, 4);

    console.log(array); // [0, 1, 2, 4]

    padStart to pad the start of an array

    Array