Final answer:
Array.slice() in JavaScript accepts two parameters, 'Start Index' and an optional 'End Index'. It creates a new array with the elements from the start index up to, but not including, the end index if provided.
Step-by-step explanation:
The Array.slice() method in JavaScript is used to return a shallow copy of a portion of an array into a new array object. This method accepts two parameters:
- Start Index: The zero-based index at which to begin extraction. If negative, it indicates an offset from the end of the sequence. If omitted, slicing starts from the beginning of the array.
- End Index (optional): The zero-based index before which to end extraction. Slicing extracts up to but not including end. If omitted or if the value is greater than the length of the array, slicing will continue until the end of the array.
The Array.slice() does not mutate the original array but instead returns a new one with the selected elements.