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)
The array to pad
The length of array once it has been padded. If this parameter is smaller than array's length, array will not be modified
array
The value to pad the array with
const array = [0, 1, 2];padEnd(array, 4, 4);console.log(array); // [0, 1, 2, 4] Copy
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
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)