From http://www.w3schools.com (Copyright Refsnes Data)
JavaScript String Object
The slice() method extracts a part of a string and returns the extracted part in a new string. Otherwise it returns -1.
| stringObject.slice(begin,end) |
| Parameter | Description |
|---|---|
| begin | Required. Where to begin the extraction. Must be a number. Starts at 0 |
| end | Optional. Where to end the extraction. If omitted, slice() selects all characters from the begin position to the end of the string |
Tip: You can use a negative numbers to select from the end of a string.
ExampleExtract different parts of a string:
The output of the code above will be:
Try it yourself » |
JavaScript String Object
From http://www.w3schools.com (Copyright Refsnes Data)