Slice usage
String.slice (NUM1, num2)
String.slice (num)
The slice () method extracts a part of the string and returns the extracted part with a new string.
return value
A new string. Includes all characters for the string stringobject from start (including start) to end ending (excluding ends).
Instance
<script language= "JavaScript" >
<!--
var myString = new String ("This is a Test");
var myslice = Mystring.slice (0,6);
document.write (' The ' the ' the ' the ' 7 characters our string, ' + myString ');
document.write (', are: ' + myslice);
Document.close ();
-->
</script>
Note: You can use negative values to select elements from the tail of the array.
Note: If end is not specified, then the slice () method selects all elements from start to ending of the array.
Instance
<script type= "text/web Effects" >
var arr = new Array (3)
Arr[0] = "George"
ARR[1] = "John"
ARR[2] = "Thomas"
document.write (arr + "<br/>")
document.write (Arr.slice (1) + "<br/>")
document.write (arr)
</script>
Output
George,john,thomas
John,thomas
George,john,thomas
In this example, we will create a new array and then display the elements selected from it:
<script type= "Text/javascript" >
var arr = new Array (6)
Arr[0] = "George"
ARR[1] = "John"
ARR[2] = "Thomas"
ARR[3] = "James"
ARR[4] = "Adrew"
ARR[5] = "Martin"
document.write (arr + "<br/>")
document.write (Arr.slice (2,4) + "<br/>")
document.write (arr)
</script>