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

duplicate

Last update:
Jun 9, 2026
Duplicates a Set value using ColdFusion's duplicate() function.

Description

Deep copy semantics for CFML data structures apply where supported.

Returns

A copy of the value.

Category

ColdFusion functions

Function syntax

duplicate(set)

Parameters

ParameterDescription
setValue to duplicate.

See also

Example

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

<cfscript>
    s = setNew();
    s.add("x");
    s.add("y");

    s2 = duplicate(s);
    s2.add("z");

    writeOutput(s.size());  // 2
    writeOutput(s2.size()); // 3
</cfscript>  
      

Real-world example

Store a snapshot of permissions in session without sharing the same set reference as application scope.

 <cfscript>
    function snapshotPermissions(required any permSet) {
        return duplicate(permSet);
    }

    live = setNew();
    live.add("EDIT");

    session.userPermissions = snapshotPermissions(live);
    live.add("DELETE");
</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