Parameters: This method accepts two parameters as mentioned above and described below:
- targetLength: It is the length of the final string once the original string has been padded. If the value is less than the original string length, then the original string is returned.
- padString: It is the string that is to be padded with the original string. If this value is too long to be within the targetLength, it is truncated from the end. The default used string is the space character (” “).
Return Value: It returns the final string that is padded with the given string to the given length.
Example 1: This example uses the padStart() method to pad strings into another string.
Example 2: This example uses the padStart() method to pad numbers into another number.
Supported Browsers: The browser supported by the padStart() method are listed below:
- Google Chrome 57
- Firefox 48
- Edge 15
- Safari 10
- Opera 44