This article mainly introduces the JavaScript in the slice () method of using the detailed, is the basic knowledge of JS learning, need friends can refer to the
This method extracts part of the string and returns a new string.
Grammar
?
1 |
String.slice (Beginslice [, Endslice]); |
The following are the details of the parameters:
Beginslice: Start extraction from zero-based index position
Endslice: Ends the extraction from the zero-based index position. If omitted, the end of the string extracted in the slice
Note: As a negative exponent, endslice represents the offset from the end of the string. String.slice (2,-1) extracts the second to last character, the third character of the string.
return value:
If successful, the slice returns the index of the regular expression within the string. Otherwise, return-1.
Example:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14-15 16 |
|
This will produce the following results:
?
1 |
Les are round, and apples are Juic |