I have a collection objects in an array,
[{A:2, B:2},{A:2, B:3},{A:1, B: 2}, {A:1, B:1}]
I would like to have a sort result of property A then property B. Therefore, as a result it should be:
[{A:1, B:1}, {A:1, B:2}, {A:2, B:2}, {A:2, B:3}]
I have a collection objects in an array,
I would like to have a sort result of property A then property B. Therefore, as a result it should be:
|
|||||
|
Sort by A then by B. This sort works, because if
Using fully cross browser sort and the benefits of lazy evaluation |
|||||||||
|
try following code
|
|||
|
You use a custom sort callback that first compares the A values and then, if those are equal uses the B values, thus creating primary and secondary keys for the sort:
|
|||
|