JavaScript .trimEnd()
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.
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:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve 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