<!DOCTYPE html> <html> <body> <h1>JavaScript Strings</h1> <h2>The trim() Method</h2> <p>trim() removes whitespace from both sides of a string:</p> <pre><p id="code1"></p></pre> <pre><p id="code2"></p></pre> <script> var text = " Hello Workingcode! "; var result = text.trim(); document.getElementById("code1").innerHTML = text; document.getElementById("code2").innerHTML = result; </script> </body> </html>
Output
JavaScript Strings
The trim() Method
trim() removes whitespace from both sides of a string:
Hello Workingcode!
Hello Workingcode!
The trim() Method JavaScript
admin Changed status to publish December 19, 2023