JavaScript String trimEnd()

Definition and usage

trimEnd() The method removes spaces from the end of the string.

trimEnd() The method does not change the original string.

trimEnd() The way the method works is trim() Similar, but only removes spaces from the end of the string.

Note:trimEnd() The method was added to JavaScript in ECMAScript 2019.

See also:

trim() method

trimStart() method

Example

let text1 = "     Hello World!     ";
let text2 = text1.trimEnd();

Try it yourself

Syntax

string.trimEnd()

Parameter

No parameters.

Return value

Type Description
String The string with spaces removed from the end.

Browser support

Since January 2020, all browsers support JavaScript String trimEnd()

Chrome Edge Firefox Safari Opera
Chrome 66 Edge 79 Firefox 61 Safari 12 Opera 50
2018 年 4 月 Janvier 2020 Juin 2018 Septembre 2018 Mai 2018

Pages associées

Chaîne JavaScript

Méthodes de chaîne JavaScript

Recherche de chaîne JavaScript