|
| JAVASCRIPT slice() METHOD
The slice() method extracts a chunk of a string between positions you specify and returns that chunk as a new string.
The general format is:
string.slice(startposition, endposition);
The startposition specifies what position to start extracting from, endposition specifies what position to stop extracting from ie. the extracted part will be from startposition inclusive to endposition exclusive. The endposition argument is optional and if it is not specified, then extraction will be from startposition to end of string.
Also remember that the first position of a string is always 0 and not 1.
Example: No endposition specified
<script type="text/javascript">
var string="The brown box is brown";
document.write(string.slice());
</script>
The above will output:
Example: endposition Specified
<script type="text/javascript">
var string="The brown box is brown";
document.write(string.slice(4, 9));
</script>
The above will output:
See Also:
|
|