var arr = [];
arr.push(row1);
arr.push(row2);
...
arr.push(rown);
How to sort by row['key']
?
![]() ![]() ![]() |
How to sort by
|
||
|
![]() ![]() ![]() |
|
||
|
![]() ![]() |
You call the sort function of an array with your comparator. A JavaScript comparator is just a function that returns -1, 0, or 1 depending on whether a is less than b, a is equal to b, or a is greater than b:
This is just an example, your function can base the comparison on whatever you want, but it needs to return -1,0,1. Hope this helps. |
||
|
![]() ![]() |
Consider the following code:
Now just change a |
||
|
![]() ![]() |
Here is set of functions if you want to sort asending, descending, or sort on multiple columns in an array.
To get an ascending sort, use "cmp(...)", and to get a descending sort, use "-cmp(...)" |
||
|