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.
var str = "poopcode "; console.log(str.trimEnd()); //poopcode console.log(str.trimRight()); //poopcode