[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1638
  • Last Modified:

sorting an Array with sortOn (ActionScript 2.0)

I have an array "multiArr" that traces out this data.

trace(multiArr.name);
Output: Jeremyville,Billie Joe Armstrong,Noemi Riebesell

trace(multiArr.id);
Output: 30,10,32

--------------------------------------------

I am trying to sort this array using the sortOn method.

multiArr.sortOn('id', Array.NUMERIC);



this should sort by the id but it is not working.
0
digitaldavenyc
Asked:
digitaldavenyc
  • 3
  • 3
1 Solution
 
scooby_56Commented:
use typeof( multiArr.id[0] );
is this numeric or a string ???

if it is a string then convert the values to numbers with parseInt();
0
 
digitaldavenycAuthor Commented:
that did not solve the problem. even if I remove Array.NUMERIC and sort ASCENDING it does not work.
0
 
scooby_56Commented:
per other post...

for an array of objects you would use sorton... i.e

var array:Array = [ {id:2,aName:"ctesting"},{id:1,aName:"atesting"},{id:8,aName:"utesting"},{id:4,aName:"qtesting"},{id:6,aName:"btesting"}]
array.sortOn("id");
trace(array[0].aName); //traces atesting - so is sorting

you are using array of numeric values.. so use sort... i.e
var array:Array = [5,2,6,4]
array.sort()
trace(array[0]) //traces 2 - which is sorting ok
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
DreammonkeyCommented:
Maybe you should post the script you are using, digitaldave.

DM
0
 
digitaldavenycAuthor Commented:
0
 
digitaldavenycAuthor Commented:
i solved this problem else where ... thanks for the input though
0
 
scooby_56Commented:
I did point out that you were sorting an array of numeric values and then went on to gave working examples of both ways.

(off-topic comment removed)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now