String.prototype.trimEnd() returns a new string with whitespace removed from the end only. Leading spaces stay. It takes no parameters. trimRight() is the same function (legacy alias).
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call string.trimEnd. Start with this line.
JavaScript
string.trimEnd()
Call
What it does
string.trimEnd()
Primary signature.
string.trimEnd(...)
Call with the arguments your case needs.
Built into JavaScript. Call trimEnd(...) on a string (or String instance) — no import required.
Library declarations
JavaScript
string.trimEnd()
Parameters
This member has no parameters beyond those shown in the signature.
Return Value
Return Value
Description
*
New string without trailing whitespace
JavaScript Examples
Example 1 — Trim the End Only
Remove trailing spaces; leave leading spaces in place.
trimEnd() clears the end. Leading spaces remain → " Hello".
trimRight() matches. It is an alias — same result as trimEnd().
Same function. The === check on the prototype methods is true.
Compatibility
Browser & Runtime Support
String.prototype.trimEnd() is part of ES2019 and is Baseline Widely available in modern browsers and runtimes. The trimRight alias is also widely supported.
✓ Baseline · ES2019
String.prototype.trimEnd()
Supported in Chrome 66+, Firefox 61+, Safari 12+, Edge 79+, and modern Node.js. Prefer trimEnd() over trimRight() in new code.
95%Modern browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
String.trimEnd()Excellent
Bottom line: Safe for modern web apps and current Node LTS. For very old engines, feature-detect or fall back to a small regex / polyfill — or use trim() when both ends are fine to clean.
Frequently Asked Questions
trimEnd() returns a new string with whitespace removed from the end (right side) only. Leading whitespace is kept. The original string is not changed.
Yes. trimRight() is an alias of trimEnd() — they are the same function. Prefer trimEnd() for consistency with padEnd().
Whitespace includes spaces, tabs, newlines, and other white space characters plus line terminators (same rules as trim()).
trim() cleans both ends. trimStart() removes only from the start. trimEnd() removes only from the end.
No. Strings are immutable. trimEnd() always returns a new string — even when there was nothing to remove.
When you must keep leading indentation or padding but want to drop trailing spaces or newlines — for example cleaning lines while preserving indent.