Favorites

JavaScript String.prototype.trimEnd() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
String.prototype.trimEnd()
JavaScript String Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

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

console.log('[' + '  text with spaces   \n'.trimEnd() + ']');

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee