Sort Json by 2 keys.


function sortJSONBy2Keys(a,b,c){var d=function(b,c){return b>c?1:b<c?-1:0};return a.sort(function(a,e){var f=a[b],g=e[b],h=a[c],i=e[c];return d([d(f,g),d(h,i)],[d(g,f),d(i,h)])})}

var sortedJson = sortJSONBy2Keys(originalJson,'key1','key2');

 

Example: https://jsfiddle.net/1934z53s/

 

Advertisements