Description
The slice() method extracts a part of a string and returns the extracted part in a new string. Otherwise it returns -1.
This method has the form:
string.slice(begin,end)
Parameter | Description |
---|---|
begin | (required) The index where to begin the extraction. First character is at index 0 |
end | (optional) Where to end the extraction. If omitted, slice() selects all characters from the begin position to the end of the string |
Examples
The following example shows the basic use of this method.
<script>
var s = "Hello from JavaScript";
// extract all chars from pos 11
document.write(s.slice(11));
</script>
This produces the following result:
Browser Support
Firefox | IE | Chrome | Opera | Safari |
---|---|---|---|---|