CKTIS / JavaScript
String.prototype.trimEnd() — removing trailing whitespace
trimEnd() returns a string without trailing whitespace and line terminators. If the string contains only those characters, it returns an empty string. The original is unchanged.
Version: ECMAScript 2019. The main ECMAScript specification defines String.prototype.trimRight as a legacy alias whose initial value is the same function object as String.prototype.trimEnd.
Syntax
str.trimEnd()String.prototype.trimEnd() removes the longest trailing sequence of whitespace and line terminators and returns the result as a string value. If the string contains a character that is neither whitespace nor a line terminator, everything up to and including the last such character is preserved. Strings are immutable: save or pass on the returned value to use the result. If the string consists entirely of characters eligible for removal, the result is an empty string.
The method takes no parameters specifying which characters to remove. It uses ECMAScript's WhiteSpace and LineTerminator sets, which include spaces, tabs, line terminators, and the non-breaking space \u00A0. It does not remove arbitrary invisible characters or a specified suffix. trimStart() works at the beginning, while trim() works at both ends.
The method is generic. When invoked through call, it throws TypeError for a null or undefined receiver before string conversion. For other receivers it applies ToString, which also throws TypeError for a Symbol primitive.
trimEnd() belongs to ECMAScript 2019, not Web APIs. The language specification is not a browser compatibility table; check availability in the target environment, for example with typeof String.prototype.trimEnd === "function". Using Node 24 in a repository alone does not establish browser support.
Examples
const original = " Ada Lovelace \t\n";
const result = original.trimEnd();
console.log(JSON.stringify(result));
console.log(result.length);
console.log(original.length);Result
" Ada Lovelace" 14 17
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.