trimEnd()
method removes whitespace from the end of a string.
trimRight()
is an alias of this method.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
str.trimEnd();
str.trimRight();
A new string representing the calling string stripped of whitespace from its (right) end.
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'
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'String.prototype.trimEnd' in that specification. |
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
更新 GitHub 上的兼容性数据| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
trimEnd
|
Chrome
66
|
Edge
12
Alternate Name
|
Firefox
61
|
IE No |
Opera
53
|
Safari 12 |
WebView Android
66
|
Chrome Android
66
|
Firefox Android
61
|
Opera Android
47
|
Safari iOS 12 |
Samsung Internet Android
9.0
|
nodejs
10.0.0
|
完整支持
不支持
使用非标名称。
String
String.fromCharCode()
String.fromCodePoint()
String.prototype.anchor()
String.prototype.big()
String.prototype.blink()
String.prototype.bold()
String.prototype.charAt()
String.prototype.charCodeAt()
String.prototype.codePointAt()
String.prototype.concat()
String.prototype.endsWith()
String.prototype.fixed()
String.prototype.fontcolor()
String.prototype.fontsize()
String.prototype.includes()
String.prototype.indexOf()
String.prototype.italics()
String.prototype.lastIndexOf()
String.prototype.link()
String.prototype.localeCompare()
String.prototype.match()
String.prototype.matchAll()
String.prototype.normalize()
String.prototype.padEnd()
String.prototype.padStart()
String.prototype.repeat()
String.prototype.replace()
String.prototype.replaceAll()
String.prototype.search()
String.prototype.slice()
String.prototype.small()
String.prototype.split()
String.prototype.startsWith()
String.prototype.strike()
String.prototype.sub()
String.prototype.substr()
String.prototype.substring()
String.prototype.sup()
String.prototype.toLocaleLowerCase()
String.prototype.toLocaleUpperCase()
String.prototype.toLowerCase()
String.prototype.toSource()
String.prototype.toString()
String.prototype.toUpperCase()
String.prototype.trim()
String.prototype.trimEnd()
String.prototype.trimStart()
String.prototype.valueOf()
String.prototype[@@iterator]()
String.raw()
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()