# array.swap()

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

```
array.swap( position1=number, position2=number )
```

**Returns:** array

# Arguments

| Argument | Type | Required | Description | Default |
|----------|------|----------|-------------|---------|
| position1 | number | Yes | Position of first element to swap |  |
| position2 | number | Yes | Position of second element to swap |  |

# Examples

```1
myarray = ["one","two","three","four","five"];
res = myarray.swap(2,4);
writeDump(res);
```

# Categories

[Arrays](../../../categories/array.md)

# See Also

[ArraySwap()](../../functions/arrayswap.md), [Array](../array.md)