trimEnd() method removes whitespace from the end of a string and returns a new string, without modifying the original string.
trimRight() is an alias of this method.
trim() was standardized, engines also implemented the non-standard method
trimRight. However, for consistency with
padEnd(), when the method got standardized, its name was chosen as
trimEnd. For web compatibility reasons,
trimRight remains as an alias to
trimEnd, and they refer to the exact same function object. In some engines this means:
String.prototype.trimRight.name === "trimEnd";
The following example trims whitespace from the end of
str, but not from its start.
let str = " foo "; console.log(str.length); // 8 str = str.trimEnd(); console.log(str.length); // 6 console.log(str); // ' foo'
|ECMAScript Language Specification |
BCD tables only load in the browser