The Substr() JavaScript:- Geniusofstudent

  • The substr() method extracts part of a string, beginning at the specified position, and returns the specified number of characters.
  • To extract characters from the end of the string, use a negative start number.
  • The substr() method does not change the original string.

Code:-
  1. <!DOCTYPE html> 
  2. <html> 
  3.  
  4. <head> 
  5.  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  6. </head> 
  7.  
  8. <body> 
  9.  
  10.  <h1>substr()</h1> 
  11.  
  12.  <input type="button" onclick="strfun();" value="Get Answer"> 
  13.  
  14.  <script> 
  15.   function strfun() 
  16.   { 
  17.    var str = "abcdefghijkl"; 
  18.    alert(str.substr(4, 5)); //Split from 4th character to 5 characters. 
  19.   } 
  20.  </script> 
  21.  
  22. </body> 
  23.  
  24. </html>
The Substr() JavaScript:- Geniusofstudent The Substr() JavaScript:- Geniusofstudent Reviewed by Network security on June 30, 2019 Rating: 5

No comments:

Useful Information

Powered by Blogger.