ArrayShift

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

Parameter

Required/Optional

Description

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

Array shift
Array shift

 Adobe

Get help faster and easier

New user?

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online