Returns part of an array with only the elements you need.
Portion of an array based on the offset and length settings.
ColdFusion 10: Added this function.
arraySlice(array,offset,length)
Parameter |
Description |
|---|---|
array |
Name of the array that you want to slice. |
offset |
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 |
Element count from offset. |

<cfscript>
array = [1, 2, 3, 4, 5, 6, 7, 8];
newArray = arraySlice(array, 2, 3);//returns 2,3,4
writeDump(newArray);
newArray = arraySlice(array, 4);//returns 4,5,6, 7, 8
writeDump(newArray);
newArray = arraySlice(array, -5, 3);//returns 4,5,6
writeDump(newArray);
</cfscript>
Output
Sign in to your account