- The substring() method extracts the characters from a string, between two specified indices, and returns the new sub string.
 - This method extracts the characters in a string between "start" and "end", not including "end" itself.
 - If "start" is greater than "end", this method will swap the two arguments, meaning str.substring(4, 1) == str.substring(1, 4).
 - If either "start" or "end" is less than 0, it is treated as if it were 0.
 - The substring() method does not change the original string.
 
Code:-
- <html>
 - <head>
 - <meta name="viewport" content="width=device-width, initial-scale=1">
 - </head>
 - <body>
 - <h1>substring()</h1>
 - <input type="button" onclick="strfun();" value="Get Answer">
 - <script>
 - function strfun()
 - {
 - var str = "abcdefghijkl";
 - alert(str.substring(4, 5)); //Split from 4th to 5th character.
 - }
 - </script>
 - </body>
 - </html>
 
How to use substring in JavaScript:- Geniusofstudent
 
        Reviewed by Network security
        on 
        
June 30, 2019
 
        Rating: 
      
 
        Reviewed by Network security
        on 
        
June 30, 2019
 
        Rating: 



No comments: