1 both methods are String object methods.
2 substr (START, length): returns a substring of the specified length starting from the specified position;
Substring (START, end): returns the substring at the specified position in the string object. The substring contains the character at the start position, not the character at the end position!
3. The substring method uses a small value of start and end as the starting point of the substring.
For example:
Substring (0, 3) and substring (3, 0) return the same substring.
If start or end is Nan or negative, replace it with 0.
The length of the substring is equal to the absolute value of the difference between start and end. For example, the length of the substring returned in substring (0, 3) and substring (3, 0) is 3. JavascriptCode
- VaRSTR ="0123456"
- Document. Write (Str. substring (0, 3 ));
- Document. Write (Str. substr (4, 1 ));
VaR STR = "0123456" document. Write (Str. substring (); document. Write (Str. substr ));
Result:
012
4