In this tutorial, you’ll learn how to use the JavaScript trim() method to remove whitespace characters from both ends of a string.

Introduction to the JavaScript trim() method

The String.prototype.trim()returns a new string stripped of whitespace characters from beginning and end of a string:


let resultString = str.trim();

The whitespace characters are space, tab, no-break space, etc.

Note that the trim() method doesn’t change the original string.

To remove whitespace characters from the beginning or from the end of a string only, you use the trimStart() or trimEnd() method.

#javascript #programming #developer #web-development

JavaScript Trim(): Remove Whitespace Characters from Both Ends
1.70 GEEK