Get Subarray Method
The Get Subarray method gets the array elements that exist in a range starting with the value that the first element argument identifies and ending with the value that the last element argument identifies. It returns a new array.
Format
slice (first element, last element)
The following table describes the arguments for the Get Subarray method.
Argument | Description |
---|---|
first element |
The first element that this method returns. |
last element |
The last element minus one that this method returns. |
Example
The following example includes the Get Subarray method:
var v = new Array;
var u;
v[0] = 7;
v[1] = 3;
v[2] = 4;
v[3] = 5;
u = v.slice ( 1, 3); // u creates new array containing v[1] and v[2] values. For
example, u[0] = 3, u[1] = 4.
v.shift(); // Now v[0] is 3, v[1] is 4