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!

1

1 Answer 1

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];
}); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.