Maybe what I asked for isn't possible. Here's a different way I could go about it also. Is there a way to sort nested arrays?
HTML Code:
<script type="text/javascript">
function sortNumber(a, b)
{
return a - b;
}
var n = [10, "winona"];
var m = [14, "alab"];
var l = [13, "greg"];
var c = [n,m,l];
document.write(c[][0].sort(sortNumber));
</script>
This doesn't work, but is there a way I can sort the arrays nm&l based on the numbers in the 0 columns of their arrays?
Isn't that what the code I have above is doing? Is 'var c' a two dimensional array? I still can't figure out how to sort that kind of array numerically.
This is as close as I have gotten. It works alphabetically only however, so if for example you change 152 to 15, it no longer is in numerical order. Any suggestions?
HTML Code:
<script type="text/javascript">
function compare(a, b) {
if (a < b) {
return 1;
}
if (a > b) {
return -1;
}
if (a == b) {
return 0;
}
}
var n = [150, "winona"];
var m = [142, "mlab"];
var l = [152, "greg"];
var c = [n,m,l];
document.write(c.sort(compare));
</script>
You are welcome! When you get the principle, everything else is up to your customization. If it interests you, you can read how to sort these 2-d arrays here: http://www.webdeveloper.com/forum/sh...ad.php?t=59157
Especially how Nedals explained this issue to me.
Bookmarks