arrayReduceRight

This function iterates over every element of the array and calls the closure to work on that element. It will reduce the array to a single value, from the right to the left, and return it.
NOTE:This function is not available in Lucee 5.x or lower. Potentially use reverse() instead.

arrayReduceRight(array, function(result, item [,index, [array]]){} [, initialValue]) → returns any

Member Function Syntax

someArray.reduceRight(function(result, item [,index, [array]]){} [, initialValue])

This function requires Adobe ColdFusion 2021 and up.  Not supported on Lucee, etc.

arrayReduceRight Argument Reference

array array
Required

The input array.

callback any
Required

Closure or a function reference that will be called for each iteration.

Callback parameters:

  • result*any : The result of the reduce operation after the previous iteration.
  • item*any : The value for the current iteration's item.
  • index*numeric : The current index for the iteration
  • array*array : A reference of the original array

initialValue any

Initial value which will be used for the reduce operation.

Links more information about arrayReduceRight

Examples sample code invoking the arrayReduceRight function

Demonstrate how the function works from right to left.

myArray=["a","b","c","d"];
newArray=arrayReduceRight(myArray,function(prev,next,idx,arr){ return prev & next & idx },"");
writedump(newArray);

Expected Result: d4c3b2a1


Fork me on GitHub