String.prototype.trimEnd()

Returns a new string with whitespace removed from the end.

Since ES2019 Spec ↗

Syntax

str.trimEnd()

Returns

string — A new string with trailing whitespace removed.

Examples

console.log('|' + '  hello  '.trimEnd());
Output
|  hello
console.log('x \t\n'.trimEnd() + '!');
Output
x!

Notes

Only trims the end; leading whitespace is preserved. `trimRight` is a legacy alias. Does not mutate the original string.

Browser & runtime support

EnvironmentSince version
chrome 66
firefox 61
safari 12
edge 79
node 10

See also