# How to swap a 2D array?

**URL:** <https://forum.kirupa.com/t/how-to-swap-a-2d-array/230043>\
**Category:** Uncategorized\
**Created:** [June 22, 2007, 6:04am UTC](https://forum.kirupa.com/t/how-to-swap-a-2d-array/230043 "2007-06-22T06:04:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sstark](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sstark/32/3702_2.png) [@sstark](https://forum.kirupa.com/u/sstark)\
**Post date:** [June 22, 2007, 6:04am UTC](https://forum.kirupa.com/t/how-to-swap-a-2d-array/230043/1 "2007-06-22T06:04:11Z")

</div>

I have a 2D array, let’s use this example:

```auto

var my_ary:Array = new Array();
my_ary[0] = [0,0,0,1,1,4,5,6];
my_ary[1] = [1,1,3,4,4,3,3,4];
my_ary[2] = [0,1,3,4,6,7,8,9];

```

I need to have a ‘swap’ function, and I have one that works great for a one dimensional array as follows:

```auto

Array.prototype.swap = function(fromIndex:int, toIndex:int):void {
    var temp:* = this[toIndex];
    this[toIndex] = this[fromIndex];
    this[fromIndex] = temp;
}

```

however this is not working for my because I want to swap array index:

my\_ary[0][3]

with

my\_ary[2][6]

Any help?
