Please help me to understand how to sort a nested array which looks like the one presented in the code below.
var arr2 = [
[["a",1,10,4],["a",3,6,7]],[["a",44,34,10]],
[["b",11,31,12],["b",110,88,77],["b",55,66,30]],
[["c",12,36,18],["c",18,66,71],["c",52,45,89]]
];
In my case each letter represents a specific product type dataset I'd like to analyse separately. Hence it is important to me to sort each "product type array" on its own. Also important to know, the number of "product type arrays" is not fixed to three. It can be more or less. So the code should be flexible enough to handle a variable number of "product type arrays".
In my example, let's say the first numeric value after product type identifier is the value I'd like to use for sorting. How can I do that?
I know how the sort function works in a less complex scenario but can't figure out how to apply this to the data above.
var arr2 = [
["a",1,10,4],["a",3,6,7],["a",44,34,10]
];
var newArr2 = arr2.sort(function(r1,r2) {
var a = r1[1];
var b = r2[1];
return a-b;
});
Thanks for your help!
Edit 20/05/20:
A more realistic data example that actually matches my data.
var arr4 = [[["hansa bank - blau", "hansa bank - blau blau", 1, 10, 9], ["hansa bank - blau", "hansa bank - blau blau", 3, 6, 7], ["hansa bank - blau", "hansa bank - blau blau", 44, 34, 10]],
[["hansa bank - grün", "hansa bank - grün grün", 11, 31, 105], ["hansa bank - grün", "hansa bank - grün grün", 110, 88, 77], ["hansa bank - grün", "hansa bank - grün grün", 55, 66, 30]],
[["hansa bank - rot", "hansa bank - rot rot", 12, 36, 33], ["hansa bank - rot", "hansa bank - rot rot", 18, 66, 12], ["hansa bank - rot", "hansa bank - rot rot", 52, 45, 89]]];