Pads an array with a given value so that the array reaches a given length. The padding is applied from the start (left) of the array.
Time complexity: O(n)
Space complexity: O(n)
The array to pad
The length of array once it has been padded. If this parameter is smaller than the current string's length, array will not be modified
array
The value to pad the array with
const array = [1, 2, 3];padStart(array, 4, 0);console.log(array); // [0, 1, 2, 3] Copy
const array = [1, 2, 3];padStart(array, 4, 0);console.log(array); // [0, 1, 2, 3]
padEnd to pad the end of an array
Array
Pads an array with a given value so that the array reaches a given length. The padding is applied from the start (left) of the array.
Time complexity: O(n)
Space complexity: O(n)