How to use the arraySlice() function in the ColdFusion?
This function returns an array in which you want to start the array element position and how many array elements you need from the start position.
arraySlice(array, offset, length)
Member Function Syntax:
someArray.slice(offset, length)
Attributes:-
array:- Name of the array that you want to slice
offset:- Specifies the position from which to slice the array. A negative value indicates that the array is sliced, with a sequence starting from the array’s end.
length:- Maximum elements to slice
Example:-
Suppose the array is:
arrayElements = [2, 3, 4, 5, 6, 7, 8, 9];
1. We have to need this array starting from 3 and the rest of the elements.
arraySlice(arrayElements, 3);
It returns:
[4, 5, 6, 7, 8, 9]
2. The function could be called as:
arraySlice(arrayElements, -5, 4);
It returns:
[5, 6, 7, 8]
3. Again, the function could be used like this:
arraySlice(arrayElements, 3, 4);
It returns:
[4, 5, 6, 7]
4. Slice an array using the member function
array.slice(3, 4);
It returns:
[4, 5, 6, 7]