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?
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?