How to use trim in JavaScript:- Geniusofstudent

  • The trim() method removes whitespace from both sides of a string.
  • The trim() method does not change the original string.



Code:-
  • <!DOCTYPE html> 
    1. <html> 
    2.  
    3. <head> 
    4.  <meta name="viewport" content="width=device-width, initial-scale=1"> 
    5. </head> 
    6.  
    7. <body> 
    8.  
    9.  <h1>trim()</h1> 
    10.  
    11.  <input type="button" onclick="strfun();" value="Get Answer"> 
    12.  
    13.  <script> 
    14.   function strfun() 
    15.   { 
    16.    var str = "   space   "; 
    17.    alert(str.trim()); //remove front and end white space 
    18.   } 
    19.  </script> 
    20.  
    21. </body> 
    22.  
    23. </html>


    How to use trim in JavaScript:- Geniusofstudent How to use trim in JavaScript:- Geniusofstudent Reviewed by Network security on July 02, 2019 Rating: 5

    No comments:

    Useful Information

    Powered by Blogger.