Open In App

TypeScript String padEnd() method

Last Updated : 22 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • targetLength: Here you have to pass the length you want the final string to be, after adding padding.
  • padString(Optional): The characters used for padding. Defaults, to spaces (‘ ‘) if not specified.

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.

Javascript




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.

Javascript




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


Output:

456000 6

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads