Remove whitespace from both sides of a string:
The alert box will display:
More "Try it Yourself" examples below.
The trim() method removes whitespace from both sides of a string.
Note: The trim() method does not change the original string.
The numbers in the table specify the first browser version that fully supports the method.
|Return Value:||A String, representing the string with removed whitespace from both ends|
For browsers that do not support the trim() method, you can remove whitespaces from both sides of a string with a regular expression: