Home >>JavaScript String Methods >JavaScript String trim() Method
JavaScript trim() method is used to remove the whitespace from both the sides of a given input string. It does not take any input arguments. It returns a new string without any leading or trailing white spaces.
Syntax:string.trim()
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
trim() | 10.0 | 9.0 | 3.5 | 5.0 | 10.5 |
<html> <body> <p>Click the button to see the Output.</p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { var str = " PHPTPOINT "; alert(str.trim()); } </script> </body> </html>
Click the button to see the Output.
<html> <body> <p>Click the button to see the Output.</p> <button onclick="myFunction1()">Try it</button> <script> function myFunction1() { var str = " Abhimanyu "; alert(str.trim()); } </script> </body> </html> <
Click the button to see the Output.