let text = "5";
let padded = text.padEnd(4,"0");
Try it Yourself »
let text = "5";
let padded = text.padEnd(4,"x");
Try it Yourself »
The padEnd()
method pads a string at the end.
The padEnd()
method pads a string with another string (multiple times) until it reaches a given length.
The padEnd()
method is a string method.
To pad a number, convert the number to a string first.
See the example below.
let numb = 5;
let text = numb.toString();
let padded = text.padEnd(4,"0");
Try it Yourself »
string.padEnd(
length, string)
Parameter | Description |
length | Required. The length of the resulting string. |
string | Optional. The string to pad with. Default is space. |
Type | Description |
A string | A String of the specified length, with the padding applied at the end. |
padEnd()
is an ECMAScript7 (ES7) feature.
ES7 (JavaScript 2016) is supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
padEnd()
is not supported in internet Explorer or Edge 17 (or earlier).
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!