# Moving objects in an array?

**URL:** <https://forum.kirupa.com/t/moving-objects-in-an-array/329051>\
**Category:** flash\
**Created:** [July 16, 2012, 11:18pm UTC](https://forum.kirupa.com/t/moving-objects-in-an-array/329051 "2012-07-16T23:18:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![denersc](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@denersc](https://forum.kirupa.com/u/denersc)\
**Post date:** [July 16, 2012, 11:18pm UTC](https://forum.kirupa.com/t/moving-objects-in-an-array/329051/1 "2012-07-16T23:18:31Z")

</div>

I have a array originated in a loop like this:

```auto

var arr:Array = [0,1,0,0,0,0,0,2];
var objectArr:Array = new Array();

for(i = 0; i<arr.length; i++) {
    if(arr* != 0) {
        var newNpc:Npc = new Npc(arr*)       
        objectArr.push(newNpc);
    }else{
        objectArr.push(0);
}  

```

and i want to, later on, change the position of a npc in the array and set the old position to zero, like:

Before: [0,objectNpc,0,0,0,0,0,objectNpc];  
After: [0,0,0,0,objectNpc,0,0,objectNpc];

I tried using splice(), but the objectNpc in the new position then has all his properties undefined instead of being the same as it was in the other position.
