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

isSet

Last update:
Jun 9, 2026
Returns true if the value is a ColdFusion Set.

Description

Determines whether a value is an array.

Returns

Boolean.

Category

ColdFusion Set helper utilities

Function syntax

isSet(value)

Parameters

ParameterDescription
valueValue to test.

See also

Example

The following example uses this API in cfscript (syntax: utils.isSet(value)).

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

    writeOutput(isSet(s)) // Returns True
</cfscript>
      

Real-world example

Normalize heterogeneous input to an array of IDs, treating Sets like arrays.

<cfscript>
    /**
    * Always returns a plain array of string IDs (empty array if nothing usable).
    */
    function normalizeIdList(required any raw) {
        // Already an array
        if (isArray(raw)) {
            return raw.map(function (id) { return trim(toString(id)); })
                .filter(function (id) { return len(id); });
        }

        // ColdFusion Set: unique members → array
        if (isSet(raw)) {
            return raw.toArray().map(function (id) { return trim(toString(id)); })
                .filter(function (id) { return len(id); });
        }

        // Single scalar
        if (isSimpleValue(raw) && len(trim(toString(raw)))) {
            return [ trim(toString(raw)) ];
        }

        // "a,b,c" style
        if (isSimpleValue(raw)) {
            var parts = listToArray(raw, ",", true, true);
            return parts.map(function (id) { return trim(toString(id)); })
                .filter(function (id) { return len(id); });
        }

        return [];
    }

    // --- examples ---

    s = setNew();
    s.add(" 1001 ");
    s.add("1002");
    s.add("1001"); // duplicate ignored by Set

    writeOutput(serializeJSON(normalizeIdList(s)));
    // ["1001","1002"]

    writeOutput(serializeJSON(normalizeIdList([2001, 2002])));
    // ["2001","2002"]

    writeOutput(serializeJSON(normalizeIdList("3001, 3002 ,,")));
    // ["3001","3002"]
</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