Suppose I have an array
var arr = [1,5,\"ahsldk\",10,55,3,2,7,8,1,2,75,\"abc\",\"huds\"];
and I try sorting it, I get something like ...>
If you have only alphabetical and integer items, you can stick with simple code:
var arr = [1,5,"ahsldk",10,55,3,2,7,8,1,2,75,"abc","huds"];
arr.sort(function(a, b)
{
if (a == b)
return 0;
var n1 = parseInt(a, 10);
var n2 = parseInt(b, 10);
if (isNaN(n1) && isNaN(n2)) {
//both alphabetical
return (a > b) ? 1 : 0;
}
else if (!isNaN(n1) && !isNaN(n2)) {
//both integers
return (n1 > n2) ? 1 : 0;
}
else if (isNaN(n1) && !isNaN(n2)) {
//a alphabetical and b is integer
return 1;
}
//a integer and b is alphabetical
return 0;
});
Working example: http://jsfiddle.net/25X2e/