StartIndex tells that from where to start the selection and should be a number and it is must in the slice() method. EndIndex tells the ending position for selection and it is optional. If EndIndex is not provided into the slice() method then slice() selects all the elements from the starting index position. It does not modify the length of the array. Here into this example code we have created an array of length five and we have applied slice() method to familiarize you with some cases.
Full example code is as follows: