I have an JavaScript arraylike this:
a[0][0] = "apple";
a[0][1] = 6.5;
a[1][0] = "orange";
a[1][1] = 4.3;
a[2][0] = "pear";
a[2][1] = 3.1;
I want to sort by the float number field in ascending order and assign the content in ascending order as well.
i.e.
a[0][0] = "pear";
a[1][1] = 3.1;
a[1][0] = "orange";
a[1][1] = 4.3;
a[2][0] = "apple";
a[2][1] = 6.5;
I have tried sorted the content but the code seems does not allow float number.
Also, I do not know how to reassign the content in ascending order. Can anyone help me?
a.sort(function(a,b){return a[1] - b[1];});
sortcalls is expected to return<0ifashould be beforeb,>0ifashould be afterb, or0if they're the same.a[i] = []anda = [].