Array.slice()
Top  Previous  Next


SWiSH Player Support
SWF5 or later - Supported Internally

Syntax
arrayName.slice(start {, end});

Arguments
start: A number indicating the index value to be used for the starting point of the slice. If a negative number is used for this argument, the starting point will be at the end of the array, for example: -1 indicates the last element in the array; -2 indicates the next to last element in the array; and so on.

end: An optional argument used to indicate the index value for the ending point of the slice. If you choose not to supply this optional argument, then all of the elements from the starting point to the last element are returned. If a negative number is used for this argument, the ending point will be at the end of the array, for example: -1 indicates the last element in the array; -2 indicates the next to last element in the array; and so on.

Returns
Nothing.

Description
Method; Returns a new array containing all of the elements from the start index value up to the end index value. The element at the ending point is not included, and the original array is not affected by the slice.

Samples
onLoad() {
  
  days = new Array();
  
  days[0] = "Sunday";
  
  days[1] = "Monday";
  
  days[2] = "Tuesday";
  
  days[3] = "Wednesday";
  
  days[4] = "Thursday";
  
  days[5] = "Friday";
  
  days[6] = "Saturday";
  
  trace(days.slice(3));
}

// displays "Wednesday,Thursday,Friday,Saturday" in the debug window



onLoad() {
  
  days = new Array();
  
  days[0] = "Sunday";
  
  days[1] = "Monday";
  
  days[2] = "Tuesday";
  
  days[3] = "Wednesday";
  
  days[4] = "Thursday";
  
  days[5] = "Friday";
  
  days[6] = "Saturday";
  
  trace(days.slice(3,-2));
}

// displays "Wednesday,Thursday" in the debug window