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
lengthRequired.
The length of the resulting string.
stringOptional.
The string to pad with.
Default is space.

Return Value

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

Browser Support

padEnd() is an ECMAScript 2017 feature.

ES2017 is supported in all modern browsers since September 2017:

Chrome 58 Edge 15 Firefox 52 Safari 11 Opera 45
Apr 2017 Apr 2017 Mar 2017 Sep 2017 May 2017

padEnd() is not supported in Internet Explorer.


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.