Javascript Sort Integers high to low properly

Hello,

I have an array or gameObjects:

var InitiativeMinis = new Array();

And each objects name is a basic intger (Stored as a string because it’s the name of the object)

I need to sort these objects based on their names, highest to lowest. Please only reply in Javascript as that’s what my entire project uses.

Here is my current sort routine which i know is wrong (it is sorting the names as strings), but that’s why I’m asking for help.

 InitiativeMinis.Sort(NameCompare);

function NameCompare(a : System.Object, b : System.Object) : int
{
return CaseInsensitiveComparer().Compare(a.name,b.name);
}

It’s sorting them as strings because you’re storing them as strings… and these strings are sorted in ascending order:

"1", "10", "11", "2", "20", "300", "9"

If you want to represent numbers as strings but still get them to be sorted as if they were numbers, add leading zeroes to the string representation. The list above would then become:

"001", "002", "009", "010", "011", "020", "300"