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

ArrayUnshift

Last update:
May 18, 2026

Description

This method adds one or more elements to the beginning of an array and returns the new length of the array.

Returns

The new size of the array.

Syntax

ArrayUnshift(array,object)
Member function
array.unshift(item)

History

ColdFusion (2021 release): Added this function.

Parameters

Parameter
Required/Optional
Description
array
Required
The array where an object is to be added.
object
Required
The object to add at the beginning of the array.

Example

Example 1
<cfscript>
    arr=["Mar","Apr","May","Jun","Jul"]
    unshifted=ArrayUnshift(arr,"Jan")
    WriteOutput(unshifted) // Returns 6
</cfscript>
Example 2
<cfscript>
    arr=["Mar","Apr","May","Jun","Jul"]
    // List as first element
    unshifted=ArrayUnshift(arr,"Jan,Feb") // Returns 6
    WriteOutput(unshifted)
</cfscript>
Example 3
<cfscript>
    arr=["Mar","Apr","May","Jun","Jul"]
    // Array as first element
    unshifted=ArrayUnshift(arr,["Jan,Feb"])
    WriteOutput(unshifted) // Returns 6
</cfscript>
Example 4
<cfscript>
 arr=["Mar","Apr","May","Jun","Jul"]
 // Struct as first element
 elem={"id":101,"name":"John"}
 unshifted=ArrayUnshift(arr,elem)
 WriteOutput(unshifted) // Returns 6
</cfscript>

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