JavaScript String trimEnd()

Example

let text1 = "     Hello World!     ";
let text2 = text1.trimEnd();
Try it Yourself »

Description

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

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

The trimEnd() method works like trim(), but removes whitespace only from the end of a string.

Note

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

See Also:

The trim() Method

The trimStart() Method

The padEnd() Method

The padStart() Method


Syntax

string.trimEnd()

Parameters

NONE

Return Value

Type Description
A stringA string with removed whitespace from the end of the string.



JavaScript String trimEnd() is supported in all browsers since January 2020:

Chrome 66 Edge 79 Firefox 61 Safari 12 Opera 50
Apr 2018 Jan 2020 Jun 2018 Sep 2018 May 2018

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.