JavaScript String padEnd()
- Previous page match()
- Next page padStart()
- Go up one level JavaScript String Reference Manual
Definition and usage
padEnd()
The method is used to pad characters at the end of a string.
padEnd()
The method uses another string (repeated multiple times) to pad the current string until it reaches the specified length.
Also see:
Note
padEnd()
The method is a string method.
If you need to pad a number, you must first convert the number to a string.
See the following examples.
Instance
Example 1
let text = "5"; let padded = text.padEnd(4,"0");
Example 2
let text = "5"; let padded = text.padEnd(4,"x");
Example 3
let numb = 5; let text = numb.toString(); let padded = text.padEnd(4,"0");
Syntax
string.padEnd(length, string)
Parameter
Parameter | Description |
---|---|
length | Required. The target length of the padded string. |
string | Optional. The string to be used for padding. The default is a space. |
Return value
Type | Description |
---|---|
String | Returns a string of specified length, padded with specified characters at the end. |
Browser support
padEnd()
It is a feature of ECMAScript 2017.
Since September 2017, all modern browsers support ES2017:
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome 58 | Edge 15 | Firefox 52 | Safari 11 | Opera 45 |
April 2017 | April 2017 | March 2017 | September 2017 | May 2017 |
Internet Explorer does not support padEnd()
.
- Previous page match()
- Next page padStart()
- Go up one level JavaScript String Reference Manual