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

Similar Reads

JavaScript String padEnd() Method
The padEnd() method in JavaScript is used to pad a string with another string until it reaches the given length. The padding is applied from the right end of the string. Syntax:string.padEnd( targetLength, padString );Parameters: This method accepts two parameters as mentioned above and described below: targetLength: It is the length of the final s
2 min read
Lodash _.padEnd() Method
Lodash _.padEnd() method is used to pad a string with another string until it reaches the given length. The padding is applied from the right end of the string. Padding characters are truncated if they exceed the length. Syntax:_.padEnd( [string = ''], [length = 0], [chars = ' '] );Parameters: string: This parameter holds the string to the pad.leng
1 min read
TypeScript String String.fromCodePoint() Method
The fromCodePoint() is an inbuilt TypeScript String method. It is mainly used to get the string value of any given Unicode point value. This method is really helpful when you want to handle characters that are not readily available through keyboard input. Syntax:String.fromCodePoint(...codePoints: number[]): stringParameters:...codePoints: An array
1 min read
What is the difference between 'String' and 'string' in TypeScript ?
Unlike JavaScript, TypeScript uses static typing, i.e. it specifies what kind of data the variable will be able to hold. Since TypeScript is a superscript of JavaScript, it also holds a distinction between a string and String. The usage of a string object in JS (or TS for that matter) is very minimal. String objects have the feature of adding a pro
4 min read
TypeScript | String charAt() Method
The charAt() method in TypeScript is used to return the character at the specified index of the string. The characters string are indexed from left to right. Syntax: string.charAt( index ) Parameter: This method accepts a single parameter as mentioned above and described below: index: It is an integer value between 0 and 1 less than the length of t
1 min read
TypeScript | String charCodeAt() Method
The charCodeAt() is an inbuilt function in TypeScript which is used to return the number indicating the Unicode value of the character at the specified index. Syntax: string.charCodeAt(index); Parameter: This method accept a single parameter as mentioned above and described below. index This parameter is an integer between 0 and 1 less than the len
1 min read
TypeScript | String concat() Method
The concat() is an inbuilt function in TypeScript which is used to add two or more strings and returns a new single string. Syntax: string.concat(string2, string3[, ..., stringN]); Parameter: This method accept a single parameter as mentioned above and described below. string2...stringN: This parameter holds the strings which will be concatenate. R
1 min read
TypeScript | String indexOf() Method
The indexOf() is an inbuilt function in TypeScript which is used to get the index within the calling String object of the first occurrence of the specified value. Syntax: string.indexOf(searchValue[, fromIndex]) Parameter: This method accepts two parameter as mentioned above and described below . searchValue: This parameter is a string representing
1 min read
TypeScript | String lastIndexOf() Method
The lastIndexOf() is an inbuilt function in TypeScript which is used to get the index within the calling String object of the last occurrence of the specified value. Syntax: string.lastIndexOf(searchValue[, fromIndex]) Parameter: This method accepts two parameter as mentioned above and described below: searchValue: This parameter is a string repres
1 min read
TypeScript String localeCompare() Method
The localeCompare() is an inbuilt function in TypeScript which is used to get the number indicating whether a reference string comes before or after or is the same as the given string in sorted order. Syntax: string.localeCompare( param ) Parameter: This method accept a single parameter as mentioned above and described. param : This parameter is a
1 min read