arraySlice

Returns a new array, from the start position up to the count of elements.

arraySlice(array, offset, length) → returns array

Member Function Syntax

someArray.slice(offset, length)

arraySlice Argument Reference

array
Required

Name of the array that you want to slice

offset
Required

Specifies the position from which to slice the array. Negative value indicates that the array is sliced, with sequence starting from array's end.

length
Default: Length of Array

Maximum elements to slice

Examples sample code invoking the arraySlice function


Simple arraySlice Example


array = [1, 2, 3, 4, 5, 6, 7, 8];
newArray = arraySlice(array, 2, 3);
writedump(newArray)

Expected Result: [2,3,4]


arraySlice with no length specified


array = [1, 2, 3, 4, 5, 6, 7, 8];
newArray = arraySlice(array, 4);
writedump(newArray)

Expected Result: [4,5,6,7,8]


arraySlice using a negative offset


array = [1, 2, 3, 4, 5, 6, 7, 8];
newArray = arraySlice(array, -5, 3);
writedump(newArray)

Expected Result: [4,5,6]


Fork me on GitHub