The trimEnd()
method removes whitespace from the end of a string. trimRight()
is an alias of this method.
str.trimEnd(); str.trimRight();
A new string representing the calling string stripped of whitespace from its (right) end.
The trimEnd()
/ trimRight()
methods return the string stripped of whitespace from its right end. trimEnd()
or trimRight()
do not affect the value of the string itself.
For consistency with functions like String.prototype.padEnd
the standard method name is trimEnd
. However, for web compatibility reasons, trimRight
remains as an alias to trimEnd
. In some engines this means:
String.prototype.trimRight.name === "trimEnd";
trimEnd()
The following example displays the lowercase string ' foo'
:
var str = ' foo '; console.log(str.length); // 8 str = str.trimEnd(); console.log(str.length); // 6 console.log(str); // ' foo'
Specification | Status | Comment |
---|---|---|
String.prototype.{trimStart,trimEnd} proposal | Stage 1 |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 66
|
? | 61
|
No | 53 | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | 66
|
66
|
? | 61
|
53 | ? | ? |
Server | |
---|---|
Node.js | |
Basic support | 10.0.0 |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd