JavaScript .trimEnd()

vanshNandwani6868998099's avatar
Published Oct 14, 2025
Contribute to Docs

The .trimEnd() method removes whitespace characters from the end (right side) of a string. It does not modify the original string but instead returns a new string with the trailing whitespace removed.

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours

Syntax

string.trimEnd();

Parameters:

The .trimEnd() method takes no parameters.

Return value:

Returns a new string with whitespace removed from the end (right side) of the original string.

Example

The following example removes whitespace from the end of a string using .trimEnd():

const message = 'Hello World ';
console.log(`Before trim: "${message}"`);
console.log(`After trimEnd: "${message.trimEnd()}"`);

Here’s the output of this code:

Before trim: "Hello World "
After trimEnd: "Hello World"

Codebyte Example

The following runnable example demonstrates the .trimEnd() method in action:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn JavaScript on Codecademy

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours