Removes the first element from an array and returns the removed element. This method changes the length of the array. If used on an empty array, an exception will be thrown.
arrayShift(array)
→ returns any
array.shift()
defaultValue
of type any
, that is returned if the array is empty.
Take an array of numbers and shift the first one off.
arr = [ 1, 2, 3 ];
el = arrayShift(arr);
writeOutput( el );
Expected Result: 1
This is the same example as above, but using a member function on the array instead of a standalone function.
arr = [ 1, 2, 3 ];
el = arr.shift();
writeOutput( el );
Expected Result: 1
Signup for cfbreak
to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.