Whatever message this page gives is out now! Go check it out!

setEach

Last update:
Jun 9, 2026
Invokes a callback once per set element (for-in iteration).

Description

Used to iterate over an array and run the function closure for each item in the array.

Returns

Void.

Category

ColdFusion Set helper utilities

Function syntax

setEach(set, callback)

Parameters

ParameterDescription
setSet to iterate.
callbackClosure or a function reference that will be called for each of the iteration.

See also

Example

The following example uses this API in cfscript (syntax: utils.setEach(set, callback)).


<cfscript>
    s = setNew();
    s.add(1);
    s.add(2);
    s.add(3);
    s.add(4);
    s.add(5);

    sum = 0;
    setEach(s, function(v) {
        sum += v;
    });
    writeOutput(sum) // 15
</cfscript>
      

Real-world example

Caching: bump counters per distinct cache key.

 
<cfscript>
    keys = setNew();
    keys.add("user:101");
    keys.add("user:202");
    keys.add("cart:9");

    invalidations = 0;
    setEach(keys, function (k) {
        // pretend: cacheDelete(k) or redis DEL
        invalidations += 1;
    });

    writeOutput(invalidations); // 2
</cfscript>
      

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page