Typescript String trimEnd method Last Updated : 14 May, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report The trimEnd method, introduced in ECMAScript 2019 (ES10), is designed to remove whitespace characters from the end of a string. These whitespace characters include spaces, tabs, and line breaks. Its primary purpose is to sanitize and normalize strings, especially user inputs or data fetched from external sources where leading or trailing whitespaces may be present unintentionally. Syntax:const trimmedString = originalString.trimEnd();Parameters:There are no parameters accepted by the trimEnd method. Return Type:After removing trailing whitespace characters, the procedure returns a new string. Example 1: Implementation to use trimEnd method to eliminate trailing whitespace from a string. JavaScript let str: string = " Hello World "; let trimmedStr: string = str.trimEnd(); console.log(trimmedStr); Output: Hello WorldExample 2: Implementation to use trimEnd method to eliminate trailing whitespace from a string in conjunction with other string operations as well. JavaScript let userInput: string = " TypeScript is great! "; let formattedInput: string = userInput.trimEnd().toUpperCase(); console.log(formattedInput); Output: TYPESCRIPT IS GREAT!Example 3: Implementation to use trimEnd method to eliminate trailing whitespace from a string and print its length for easy understanding. JavaScript let str = " GeeksforGeeks "; console.log(str.length); // 19 str = str.trimEnd(); console.log(str.length); // 16 console.log(str); // ' GeeksforGeeks' Output: 1916 GeeksforGeeksExample 4: Using trimEnd with Regular Expressions JavaScript let stringWithNumbers: string = "12345 "; let trimmedNumbers: string = stringWithNumbers.replace(/\d+$/,''); console.log(trimmedNumbers); Output: 12345Browser Support:Google ChromeEdge FirefoxOperaSafari Comment More infoAdvertise with us Next Article Typescript String trimEnd method P pankajbind Follow Improve Article Tags : TypeScript Similar Reads TypeScript String trim() Method The TypeScript String trim() method is used to remove whitespace from both sides of a string. This method is also available in JavaScript because it is a subset of TypeScript. It returns a new string without leading or trailing spacesSyntaxstring.trim()Parameters:This method does not take any parame 2 min read TypeScript String substring() Method The substring() is an inbuilt function in TypeScript that returns the subset of a String object. It takes two parameters: indexA (starting index) and optional indexB (ending index, non-inclusive). It returns the portion of the string between these indices.Syntaxstring.substring(indexA, [indexB]) Par 2 min read TypeScript String substr() Method The String.substr() method in TypeScript is an inbuilt function used to extract a portion of a string, starting at a specified index and extending for a given number of characters.Syntax: string.substr(start[, length])Parameter: This method accepts two parameters as mentioned above and described bel 3 min read TypeScript String padEnd() method The String.prototype.padEnd() method in TypeScript is used to pad the current string with another string (repeated, if needed) so that the resulting string reaches a given length. The padding is applied from the end (right side) of the current string. This method is useful for creating strings of un 2 min read TypeScript String slice() The slice() is an inbuilt function used to extract a section of a string and return a new string. Syntax: string.slice( beginslice [, endSlice] )Parameters: This method accepts two parameters as mentioned above and described below: beginSlice: This parameter is the zero-based index at which to begin 1 min read Like