JavaScript substring() Method
Javascript substring ( ) Definition and Usage
The Javascript substring() method extracts the characters in a string between two specified indices.
Javascript substring ( ) Syntax
| stringObject.substring(start,stop) |
Parameter |
Description |
start |
Required. Where to start the extraction. Must be a numeric value |
stop |
Optional. Where to stop the extraction. Must be a numeric value |
Javascript substring ( ) Tips and Notes
Note: To extract characters from the end of the string, use a negative start number.
Note: The start index starts at 0.
Note: If the stop parameter is omitted, this method extracts to the end of the string.
Javascript substring ( ) Example
In this example we will use substring() to extract some characters from a string:
<script type="text/javascript">
var str="Hello world!" document.write(str.substring(3))
</script> |
The output of the code above will be:
Javascript substring ( ) Example
In this example we will use substring() to extract some characters from a string:
| <script type="text/javascript"> var str="Hello world!" document.write(str.substring(3,7)) </script> |
The output of the code above will be:
|