json对象数组按对象属性排序

    //json对象数组按对象属性排序  
    function JsonSort(obj, field, sortby) {
        this.obj = obj;
        this.field = field;
        this.sortby = sortby;
    } 
 
    JsonSort.prototype.sort = function () {
        var $this = this;
        var ascend = function (a, b) {
            return parseInt(a[$this.field]) > parseInt(b[$this.field]) ? 1 : -1;
        };
        var descend = function (a, b) {
            return parseInt(a[$this.field]) > parseInt(b[$this.field]) ? -1 : 1;
        };
        if (this.sortby == "ascend") {
            this.obj.sort(ascend);
        } else {
            this.obj.sort(descend);
        }
    };

var jsonSort = new JsonSort(productJsonList, 'sortindex', 'ascend');
jsonSort.sort();

原文地址:https://www.cnblogs.com/shy1766IT/p/5185162.html