slice - Returns Selected Elements in a Array in JavaScript

The slice method returns the selected elements in an array, as a new array object.

<script type="text/javascript">
numArray = new Array(3,2,5,9);

selectedNumArray = numArray.slice(1,3);

document.write("newNumArray contains the numbers: ",selectedNumArray,"<br>");
</script>

General Syntax
Array.slice(start,[end]);

Parameter Description
start - Required. - An integer that specifies where to start the selection (Starts from 0). Use negative numbers to select from the end of an array
end - Optional. An integer that specifies where to end the selection. If omitted, all elements from the start position and to the end of the array will be selected. Use negative numbers to select from the end of an array

Example 2 : Usage of Slice with Negative index
<script type="text/javascript">
var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
var myBest = fruits.slice(-3,-1); 
document.write(myBest);
</script>