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

ArraySwap

Last update:
May 18, 2026

Description

Swaps array values of an array at specified positions. This function is more efficient than multiple cfset tags.

Returns

The function operates in-place and returns a boolean ("YES" or "NO") to indicate the success or failure of the operation.

Category

Function syntax

ArraySwap(array, position1, position2)

See also

Functions for XML object management in Modifying a ColdFusion XML object in the Developing ColdFusion Applications

Parameters

Parameter
Description
array
Name of an array
position1
Position of first element to swap
position2
Position of second element to swap

Example

<cfscript>
    superheroArray = ["Batman","Aquaman","Thor","Black Panther","Iron Man"];
    writeOutput("Original array");
    writeDump(superheroArray);
    // Swap eelements 1 and 3
    arraySwap(superheroArray,1,3);
    writeOutput("Updated array");
    writeDump(superheroArray);
</cfscript>
Output

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