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.

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
newArray = arraySlice(array, 4);//returns 4,5,6, 7, 8
newArray = arraySlice(array, -5, 3);//returns 4,5,6
</cfscript>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy