Open In App

TypeScript String padEnd() method

The padEnd() method, in TypeScript, is the opposite of padStart() which can be used to insert characters at the end of a string. Unlike its counterpart padStart() it also focuses on adding padding at the string’s conclusion to maintain uniformity.

Syntax:

string.padEnd(targetLength: number, padString?: string): string

Parameters:

Return Value:

Returns a new string of the specified targetLength with the padString applied at the end of the current string.



Example 1: The below code is a basic implementation of the padEnd() method.




let originalStr: string = "GeeksforGeeks";
let paddedStr: string = originalStr.padEnd(20);
console.log(paddedStr, paddedStr.length);

Output:



GeeksforGeeks 20

Example 2: The below code adds a padding as 0 to the given string till the length of 6.




let numberString: string = "456";
let paddedNumber: string =
    numberString.padEnd(6, "0");
console.log(paddedNumber, paddedNumber.length);

Output:

456000 6
Article Tags :