contents   index   previous   next



Array slice()

syntax:

array.slice(start[, end])

where:

start - the element offset to start from.

 

end - the element offset to end at.

 

return:

object - a new array containing the elements of the current object from start up to, but not including, element end.

 

description:

This method creates a subset of the current array. If end is not supplied, then the length of the current object is used instead. If either start or end is negative, then it is treated as an offset from the end of the array, and the value length+start or length+end is used instead. If either is beyond the length of the array, then the length is used instead. If either is less than 0 after adjusting for negative values, then the value 0 is used instead. The elements are then copied into the newly created array, starting at start and proceeding to (but not including) end.

 

see:

String substring()

 

example:

// The following code:

 

var array = new Array( 1, 2, 3, 4 );

Screen.writeln( array.slice( 1, -1 ) );

 

// Print out the elements from 1 up to 4,

// which results in the string "2,3".

 


Array sort()