JavaScript String.prototype.trimEnd() Method
The trimEnd() method removes white space from the end of a string only.
Description
The trimEnd() method removes trailing white space, including line breaks, and leaves the start alone. It is also available as trimRight().
It's handy when processing text line by line, such as removing trailing spaces from lines of a file or the final line break from command output, while keeping intentional indentation at the start.
Like the other trim methods, it removes all kinds of white space and line terminators, but not other characters. To remove a specific trailing character, such as a final comma or slash, use a regular expression like str.replace(/,$/, ''), or check with endsWith() and slice it off.
Syntax
string.trimEnd()Return Value
A new string with white space removed from the end.
Example
Browser Support
The following information will show you the current browser support for the String.prototype.trimEnd() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





