I need to sort out element in a nested array.
In each nest array there is 1 string and 1 integer.
var arr1 = [["2000", 2], ["11", 2], ["11", 2], ["10003", 4], ["22", 4], ["123", 6], ["1234000", 10], ["44444444", 32], ["9999", 36]]
I need to sort out the array by ascending integer (not the string). Which I can do by doing this:
var res = arr1.sort(function(a, b) {
return a[1] - b[1];
});
However, when 2 integers have the same value, I need to sort them by their string (only for the matching integers, not for the rest of the array).
The result should be:
[["11", 2], ["11", 2], ["2000", 2], ["10003", 4], ["22", 4], ["123", 6], ["1234000", 10], ["44444444", 32], ["9999", 36]]
I can't figure how to make this happen. I tried a for loop but keep getting an error.
Anyone to help me on this?
Thanks!