Jsref Substr
# JavaScript substr() Method
[ JavaScript String Object](#)
## Example
Extract a specified number of characters:
var str="Hello world!";
var n=str.substr(2,3)
_n_ Output:
llo
[Try it Β»](#)
* * *
## Definition and Usage
The substr() method extracts a part of a string, starting at a specified character position, and returns a specified number of characters.
**Tip:** The substr() method's parameters specify the starting position and length of the substring. Therefore, it can be used as an alternative to substring() and slice().
In IE 4, the start parameter value was invalid. In this bug, start specified the position of the 0th character. This bug was fixed in later versions.
ECMAscript does not standardize this method, so its use is discouraged.
**Note:** The substr() method does not change the original string.
* * *
## Browser Support

The substr() method is supported by all major browsers.
* * *
## Syntax
_string_.substr(_start_,_length_)
## Parameter Values
| Parameter | Description |
| :--- | :--- |
| _start_ | Required. The starting position of the substring to extract. Must be a number. If negative, this parameter specifies the position from the end of the string. That is, -1 refers to the last character of the string, -2 refers to the second last character, and so on. |
| _length_ | Optional. The number of characters in the substring. Must be a number. If omitted, the substring from the start position to the end of the string is returned. |
## Return Value
| Type | Description |
| --- | --- |
| String | A new string containing the extracted part of the text |
## Technical Details
| JavaScript Version: | 1.0 |
| --- |
* * *
## More Examples
## Example
In this example, we will use substr() to extract some characters from the second position of the string:
var str="Hello world!";
var n=str.substr(2)
_n_ Output:
llo world!
[Try it Β»](#)
* * JavaScript String Object](#)
YouTip