JavaScript String padStart() method
pads start of string until it reaches a given length

padStart() method returns a new string that pads the start of the original string until it reaches a given length.

syntax

padStart(length, string)

length The length of the resulting string once the current string has been padded.

If the value is less than or equal to string.length, the current string will be returned as-is.

string (optional). The string to pad the current string with.

If string is too long to stay within target length, it will be truncated from the end.

padStart() method does not change the value of the original string.

padStart() method pads a string with another string (multiple times) until it reaches a given length.

The length of the string is the length after it has been padded.

syntax 1 description
pad start of string with space character until the string reaches the given length
myString.padStart(length)
syntax 2 description
pad start of string with a specified string until the string reaches the given length
myString.padStart(length, string)