Skip to content

Trim white spaces at the end of the string in JavaScript

Similar to trimming spaces at the beginning of a string, we can also trim the spaces at the end of a string.

To trim white spaces at the end of a string we can use trimEnd() method. This method returns a new string with white spaces removed and it do not alter the original value of a string. trimRight() is the alias of this method.

Advertisements
var str = "poopcode   ";

console.log(str.trimEnd());
//poopcode
console.log(str.trimRight());
//poopcode
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.