String.slice() (Method)

Returns a sub-string sliced out of the original.

Availability:

ECMAScript edition - 3
JavaScript - 1.2
JScript - 3.0
Internet Explorer - 4.0
Netscape - 4.0
Netscape Enterprise server - 2.0
Property/method value type:String primitive
JavaScript syntax:-myString.slice(startPos)
-myString.slice(startPos, endPos)
Argument list:endPosThe ending character position
startPosThe starting character position

The sub-string is identified using the parameters passed as arguments in the method call.

The second argument is optional. If it is missing then it is assumed to mean the end of the string.

Example code:

   <HTML>

   <HEAD>

   </HEAD>

   <BODY>

   <SCRIPT>

   myString = "AAABBBCCCAAABBBCCC";

   myIndex = myString.lastIndexOf("AAA");

   document.write(myString.slice(myIndex, myIndex+4));

   </SCRIPT>

   </BODY>

   </HTML>

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

insert figure 0094

Cross-references:

ECMA 262 edition 3 - section - 15.5.4.13