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() How the method works 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

Starting from January 2020, all browsers support JavaScript String trimEnd():

Chrome Edge Firefox Safari Opera
Chrome 66 Edge 79 Firefox 61 Safari 12 Opera 50
April 2018 January 2020 June 2018 September 2018 May 2018

Related Pages

JavaScript String

JavaScript String Methods

JavaScript String Search