- 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:-
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- </head>
- <body>
- <h1>substr()</h1>
- <input type="button" onclick="strfun();" value="Get Answer">
- <script>
- function strfun()
- {
- var str = "abcdefghijkl";
- alert(str.substr(4, 5)); //Split from 4th character to 5 characters.
- }
- </script>
- </body>
- </html>
The Substr() JavaScript:- Geniusofstudent
Reviewed by Network security
on
June 30, 2019
Rating:
No comments: