Answer the question
In order to leave comments, you need to log in
How to sort an array by multiple values?
Hello! There is a simple JS code:
vals = vals.sort(
function(a, b) {return a[1] - b[1]}
);
Answer the question
In order to leave comments, you need to log in
vals = vals.sort(
function(a, b) {
if (a[1] == b[1]) {
return a[0] - b[0];
} else return a[1] - b[1];
}
);
vals = vals.sort(
function(a, b) { return a[1] == b[1] ? a[0] - b[0] : a[1] - b[1]; }
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question