Sort JSON alphabetically

前端 未结 5 1141
我寻月下人不归
我寻月下人不归 2021-01-02 13:08

I have a JSON object generated based on data stored in a table. I then need to be able to sort it in different ways, but when I do JSON.stringify(array) and try

5条回答
  •  暖寄归人
    2021-01-02 13:23

    Something of this kind might be on help:

    function (obj) {
       var a = [],x;
       for(x in obj){ 
         if(obj.hasOwnProperty(x)){
             a.push([x,obj[x]]);
         }
       }
       a.sort(function(a,b){ return a[0]>b[0]?1:-1; })
       return a;
    }
    
    

提交回复
热议问题