# sortOn Messing Up my Arrays

**URL:** <https://forum.kirupa.com/t/sorton-messing-up-my-arrays/319563>\
**Category:** flash\
**Created:** [February 24, 2011, 6:15pm UTC](https://forum.kirupa.com/t/sorton-messing-up-my-arrays/319563 "2011-02-24T18:15:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lethalmugshots](https://avatars.discourse-cdn.com/v4/letter/l/2acd7d/32.png) [@lethalmugshots](https://forum.kirupa.com/u/lethalmugshots)\
**Post date:** [February 24, 2011, 6:15pm UTC](https://forum.kirupa.com/t/sorton-messing-up-my-arrays/319563/1 "2011-02-24T18:15:44Z")

</div>

Hi there,

I’m using the .sortOn() function in AS3.0 to sort an array with multiple elements.

First, I push the values to the array, like this:

```auto
standingsQSR.push({pts: ptsVal, nam: namTemp, goal: target}); //push values to array

```

Then I sort it, like this:

```auto
standingsQSR.sortOn(["pts", "nam", "goal"], Array.DESCENDING); //sort array

```

The program has a number of “loops” it goes through. So, I push data to this array (which is global) a first time, sort it, and then later I clear the array with the .shift() function in conjunction with a for loop. I then push new data to the array with the same line of code mentioned above.

But what’s happening is this: on the first round, everything works great, and this is what my output looks like:

```auto
standingsQSR[0].nam = West
standingsQSR[1].nam = Central
standingsQSR[2].nam = East
//sortOn Function appears here in code.
standingsQSR[0].nam = East
standingsQSR[1].nam = Central
standingsQSR[2].nam = West

```

^  
This is correct.

Then on the second round:

```auto
standingsQSR[0].nam = BC
standingsQSR[1].nam = Southern Alberta
standingsQSR[2].nam = Northern Alberta & Prairies [correct data]
//exact same sortOn function here
standingsQSR[0].nam = BC
standingsQSR[1].nam = Northern Alberta & Prairies
standingsQSR[2].nam = Northern Alberta & Prairies [ah!!]

```

What the heck?

Before I cleared the array with for loop and .shift(), it would say “Northern Alberta & Prairies” in ALL array slots. Since I started using the .shift() function I managed to get BC to remain, but it’s still clearing my southern alberta entry.

Any ideas as to what’s happening? Many thanks!!
