0

I have a multidimension array:

var somearray = new Array(
["110", "210", "310"] ,
["020", "120", "220"] ,
["020", "120", "200"] ,
["010", "120", "230"] ,
["130", "220", "310"] ,
["103", "113", "123"] ,
...
);

And I want to sort it with priority of first column, then second column then third column. How can I do that methodologically? Thanks!

Steve H.
  • 6,912
  • 2
  • 30
  • 49
sooon
  • 4,718
  • 8
  • 63
  • 116

1 Answers1

7

Simple:

somearray.sort(function(a,b){
  if (a[0]!=b[0]) return a[0]-b[0];
  if (a[1]!=b[1]) return a[1]-b[1];
  return a[2]-b[2];
}); 
Chris Charles
  • 4,406
  • 17
  • 31