Whatever message this page gives is out now! Go check it out!

ArraySlice

Last update:
May 18, 2026

Description

Returns part of an array with only the elements you need.

Returns

Portion of an array based on the offset and length settings.

History

ColdFusion 10: Added this function.

Category

Syntax

arraySlice(array,offset,length)

Properties

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.

Example

<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

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page