How to use the arrayShift function in the ColdFusion?
ArrayShift is a ColdFusion function that helps you remove the first element from the array and return the element that is removed. This function removes the first index and shifts down the rest of the indices. If you use an empty array, then you get an exception.
Syntax
ArrayShift(array)
or
array.shift()
<cfscript>
arr=["Jan","Feb","Mar","Apr","May"];
shiftedElement=ArrayShift(arr);
WriteOutput(shiftedElement); // Returns Jan
</cfscript>
<cfscript>
arr=["Jan","Feb","Mar","Apr","May"];
shiftedElement=arr.shift();
WriteOutput(shiftedElement); // Returns Jan
</cfscript>
<cfscript>
arr=[{"id":101,"name":"John"},
{"id":102,"name":"Paul"},
{"id":103,"name":"George"}
];
shifted=ArrayShift(arr);
WriteDump(shifted);
</cfscript>