arrayUnshift

This function adds one or more elements to the beginning of the original array and returns the length of the modified array.

arrayUnshift(array,object) → returns numeric

Member Function Syntax

array.unshift(object)

Argument Reference

array array
Required

The original array to be added to.

object any
Required

The new object to be added.

Compatibility

ColdFusion:

Version 2021+ The full function was added in ACF 2021, but the member function appears to work in ACF 2018 (likely using Java).

Links more information about arrayUnshift

Examples
Sample code invoking the arrayUnshift function

Add a new element to an array.

arr=[1,2,3];
newArrLen=arrayUnshift(arr,0);
writeOutput(newArrLen);

Expected Result: 4

This is the same example as above, but using a member function on the array instead of a standalone function.

arr=[1,2,3];
newArrLen=arr.unshift(0);
writeOutput(newArrLen);

Expected Result: 4

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub