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)

arrayUnshift 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).

Lucee:

Version 5+ Implemented in 5.3.8.104-SNAPSHOT

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


Fork me on GitHub