Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sortOn and numbers 2

Status
Not open for further replies.

BriceJ

Programmer
Apr 22, 2003
6
US
I am trying to sort an associative array based on a field that has numbers using the sortOn method. The problem is that the sort is sorting on the first digit, like it was treating the number like a string. However, I am converting the number to a number before sorting using Number(). Here is an example below (if the wording above is as confusing as it reads).

var name = group_name;
var id = group_id;
id = Number(id);
var location = group_loc;
myArray.push({name:name, id:id, location:location});
myArray.sortOn("id");

And if the id's I have are say 7, 12, 3, 1, then the order after sort would be 1, 12, 3, 7. It seems like a simple solution, but I can't seem to find it. Can anyone help?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top