YouTip LogoYouTip

Jsref Substring

# JavaScript substring() Method [![Image 8: String Object Reference Manual](#) JavaScript String Object](#) * * * ## Definition and Usage The substring() method is used to extract characters between two specified indices in a string. The substring() method returns the substring including the character at the _start_ index, but excluding the character at the _end_ index. ## Syntax _string_.substring(from, to) | Parameter | Description | | :--- | :--- | | from | Required. A non-negative integer specifying the position of the first character of the substring in the string object. | | to | Optional. A non-negative integer specifying the position one greater than the last character of the substring in the string object. If this parameter is omitted, the substring will extend to the end of the string. | * * * ## Browser Support ![Image 9: Internet Explorer](#)![Image 10: Firefox](#)![Image 11: Opera](#)![Image 12: Google Chrome](#)![Image 13: Safari](#) All major browsers support the substring() method. * * * ## Example ## Example In this example, we will use substring() to extract some characters from a string: var str="Hello world!"; document.write(str.substring(3)+"
"); document.write(str.substring(3,7)); The output of the above code is: lo world! lo w [Try it yourself Β»](#) * * JavaScript String Object](#)
← Jsref Regexp Charset NotJsref Substr β†’