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

stringReduceRight(string, callback, initialValue) → returns any

Member Function Syntax

string.reduceRight(callback, initialValue)

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

Argument Reference

string string

The input string.

callback any

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 stringReduceRight

Sample code invoking the stringReduceRight function

Demonstrate how the function works from right to left.

newString=stringReduceRight(myString,function(prev,next,idx,arr){ return prev & next & idx },"")

Expected Result: d4c3b2a1

This function will be added to Lucee in Version 6. But if you need to reverse a string now, use the reverse() function.


Expected Result: dcba

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

Fork me on GitHub