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

ArrayShift

Last update:
May 18, 2026

Description

Removes the first element of an array and returns the element that is removed. This method removes the element at the first index and shifts the values at consecutive indexes down. If you use ArrayShift in an empty array, you get an exception.

Returns

The shifted element.

Syntax

ArrayShift(array)
Member function
array.shift()

History

ColdFusion (2021 release): Added this function.

Parameters

ParameterRequired/OptionalDescription
array
Required
The array to update.
Note:
If the array is empty, there is an exception.

Example

Example 1
<cfscript>
    arr=["Jan","Feb","Mar","Apr","May"]
    shiftedElement=ArrayShift(arr)
    WriteOutput(shiftedElement) // Returns Jan
</cfscript>
Example 2
<cfscript>
    arr=[{"id":101,"name":"John"},
         {"id":102,"name":"Paul"},
         {"id":103,"name":"George"}
        ]
    shifted=ArrayShift(arr)
    WriteDump(shifted)
</cfscript>
Output
Figure: Array shift
Array shift

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