JavaScript (ES2026) reference · String Methods
JavaScript String trimEnd() Method
Remove whitespace (spaces, tabs, line breaks) from the end of a string only, leaving the start untouched.
JavaScript (ES2026) Since ES2019
Syntax
string.trimEnd()
Return value
A new string.
Examples
console.log(JSON.stringify(" text ".trimEnd()));
Output
" text"
const lines = "a \nb \n";
console.log(lines.split("\n").map((l) => l.trimEnd()));
Output
[ 'a', 'b', '' ]
Version history
| Version | Change |
|---|---|
| JavaScript ES2019 | Added |
In other languages
str.rstrip()· Pythonrtrim()· PHP
Related
string.trim()· Remove whitespace (spaces, tabs, line breaks) from both ends of a string.string.trimStart()· Remove whitespace (spaces, tabs, line breaks) from the start of a string only, leaving the end untouched.- JavaScript Strings · tutorial
- JavaScript String Methods · tutorial