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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

string.trimEnd()

Return value

A new string.

Examples

Trim the endTry it yourself
console.log(JSON.stringify("  text  ".trimEnd()));

Output

"  text"
Trailing spaces per lineTry it yourself
const lines = "a  \nb \n";
console.log(lines.split("\n").map((l) => l.trimEnd()));

Output

[ 'a', 'b', '' ]

Version history

VersionChange
JavaScript ES2019Added

In other languages

Was this page helpful?