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

clone

Last update:
Jun 9, 2026
Returns a copy of the set object.

Description

Shallow copy of the set container; membership changes on the copy do not affect the original.

Returns

A Set.

Category

ColdFusion Set member methods

Function syntax

set.clone()

Parameters

ParameterDescription
None.

See also

Example

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

 <cfscript>
    original = setNew("ordered");
    original.add("a");
    original.add("b");

    copy = original.clone();
    copy.add("c");

    writeOutput(original.size()); // 2
    writeOutput(copy.size());     // 3
</cfscript>
      

Real-world example

Simulate permission revocation on a trial copy without mutating the live session set.

<cfscript>
    function simulateRevoke(required any currentPerms, required any toRemove) {
        var trial = currentPerms.clone();
        setRemoveAll(trial, toRemove);
        return trial;
    }

    current = setNew();
    current.add("READ");
    current.add("WRITE");
    current.add("ADMIN");

    remove = setNew();
    remove.add("ADMIN");

    trial = simulateRevoke(current, remove);
    writeOutput(current.has("ADMIN")); // true — unchanged
    writeOutput(trial.has("ADMIN"));   // false
</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