目录

JavaScript String padEnd()

Examples

let text = "5";
let padded = text.padEnd(4,"0");
Try it Yourself »
let text = "5";
let padded = text.padEnd(4,"x");
Try it Yourself »

Description

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.

See Also:

The padStart() Method

The trim() Method

The trimEnd() Method

The trimStart() Method

Note

The padEnd() method is a string method.

To pad a number, convert the number to a string first.

See the example below.

Example

let numb = 5;
let text = numb.toString();
let padded = text.padEnd(4,"0");
Try it Yourself »

Syntax

string.padEnd( length, string)

Parameters

Parameter Description
length Required.
The length of the resulting string.
string Optional.
The string to pad with.
Default is space.

Return Value

Type Description
A string A String of the specified length, with the padding applied at the end.

Browser Support

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).