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

setToArray

Last update:
May 18, 2026
Converts a Set to a ColdFusion array.

Description

Converts a set to a ColdFusion array. Unordered sets have no order; ordered sets follow insertion order.

Returns

Array.

Category

ColdFusion Set member methods

Function syntax

set.toArray()
setToArray(set)

Parameters

ParameterDescription
setSet to convert (BIF form).

See also

Example

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

<cfscript>
    s = setNew("ordered");
    s.add("z");
    s.add("a");
    arr = s.toArray();
    // ordered: z then a
    writeOutput(arrayLen(arr)); // 2
</cfscript>
      

Real-world example

Serialize unique tags as JSON for a REST response.

  <cfscript>
    function uniqueTagsArray(required any tagSet) {
        return tagSet.toArray();
    }

    tags = setNew();
    tags.add("cfml");
    tags.add("api");

    out=serializeJSON({ "tags": uniqueTagsArray(tags) });
    writeOutput(out)
</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