New array functions in ColdFusion (2021 release)
Adobe ColdFusion (2021 release) includes a few new array functions. In this post, I shall list (pun unintended!) the new functions and also include the CFFiddle links so that you can also try out the functions before productionizing them.
ArrayPush
Adds an element or an object to the end of an array. For more information, see ArrayPush.
Syntax
ArrayPush(array,value)
Example 1
<cfscript>
arr=[23,65,187,81,9]
ArrayPush(array=arr,value=17)
WriteOutput("The size of the array is now: " & arrayLen(arr))
</cfscript>
Example 2
<cfscript>
arr=[{"id":101,"name":"John"},
{"id":102,"name":"Paul"},
{"id":103,"name":"George"}
]
ArrayPush(arr,{"id":104,"name":"Ringo"})
WriteOutput("The size of the array is now: " & arrayLen(arr))
</cfscript>
ArrayPop
Removes the last element from an array. For more information, see ArrayPop.
Syntax
ArrayPop(array)
Example
<cfscript>
arr=[{"id":101,"name":"John"},
{"id":102,"name":"Paul"},
{"id":103,"name":"George"}
]
// Array push
ArrayPush(arr,{"id":104,"name":"Ringo"})
// Array pop
WriteDump(ArrayPop(arr))
writeDump(arr)
</cfscript>
ArrayShift
Removes the first element of an array and returns the element that is removed. For more information, see ArrayShift.
Syntax
ArrayShift(array)
Example
<cfscript>
arr=[{"id":101,"name":"John"},
{"id":102,"name":"Paul"},
{"id":103,"name":"George"}
]
shifted=ArrayShift(arr)
WriteDump(shifted)
</cfscript>
ArrayUnshift
Adds one or more elements to the beginning of an array and returns the new length of the array. For more information, see ArrayUnshift.
Syntax
ArrayUnshift(array,object)
Example 1
<cfscript>
arr=["Mar","Apr","May","Jun","Jul"]
// List as first element
unshifted=ArrayUnshift(arr,"Jan,Feb") // Returns 6
WriteOutput(unshifted)
</cfscript>
Example 2
<cfscript>
arr=["Mar","Apr","May","Jun","Jul"]
// Array as first element
unshifted=ArrayUnshift(arr,["Jan,Feb"])
WriteOutput(unshifted) // Returns 6
</cfscript>
ArrayReduceRight
Iterates over every entry of the array and calls the closure to work on the elements of the array. For more information, see ArrayReduceRight.
Syntax
ArrayReduceRight(array, function(result, item, [,index, array])[, initialValue])
Example 1
<cfscript>
data = ['1','2','3','4','5','6'];
stringConcat = ArrayReduceRight(data,function(previous,next) {
return previous & next;
},"");
writeOutput(stringConcat)
</cfscript>
Example 2
<cfscript>
data=[3,5,7,9,11]
result=ArrayReduceRight(data,function(previous,next){
return previous & next
},"")
writeDump(result)
</cfscript>

