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

has

Last update:
May 18, 2026
Returns whether the set contains a given element.

Description

Tests membership using the set's equality rules (case-sensitive for default sets; case-insensitive for nocase variants).

Returns

Boolean.

Category

ColdFusion Set member methods

Function syntax

set.has(element)

Parameters

ParameterDescription
elementThe value to test.

See also

Example

The following example uses this API in cfscript (syntax: set.has(element)).

<cfscript>
    s = setNew();
    s.add("apple");
    s.add("banana");

    writeOutput(s.has("apple"));  // true
    writeOutput(s.has("orange")); // false

    nc = setNew("nocase");
    nc.add("Hello");
    writeOutput(nc.has("HELLO")); // true
</cfscript>
      

Real-world example

Check whether a feature flag code is enabled before running expensive reporting code.

 <cfscript>
    /**
    * Returns true if a feature is enabled for the given code.
    * Flags stored in a set for O(1) average lookup.
    */
    function isFeatureEnabled(required string featureCode, required any enabledSet) {
        return enabledSet.has(featureCode);
    }

    enabled = setNew();
    enabled.add("BETA_REPORTS");
    enabled.add("NEW_CHECKOUT");

    if (isFeatureEnabled("BETA_REPORTS", enabled)) {
        writeOutput("Show beta reports UI.");
    }
</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