String.substr() (Method)

Returns a sub-string extracted from the original.

Availability:

ECMAScript edition - 3
JavaScript - 1.2
JScript - 3.0
Internet Explorer - 4.0
Netscape - 4.0
Netscape Enterprise server - 3.0
Property/method value type:String primitive
JavaScript syntax:-myString.substr(aStartPosition)
-myString.substr(aStartPosition, aLength)
Argument list:aStartPositionThe index of the first character in the substring
aLengthThe length of the substring

This is a variation of the String.substring() method. The difference is that the substring length is passed as the second argument rather than the substring ending character index.

Example code:

   <HTML>

   <HEAD>

   </HEAD>

   <BODY>

   <SCRIPT>

   myString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

   myIndex = myString.indexOf("MN");

   document.write(myString.substr(myIndex, 5));

   </SCRIPT>

   </BODY>

   </HTML>

See also:String.slice(), String.split(), String.substring()

Cross-references:

ECMA 262 edition 3 - section - B.2.3