test1 = [{"name":"tank","total":"100"},{"name":"zhang","total":"23"},{"name":"hao","total":"325"}]; sort_by = function(field, reverse, primer){ //定义排序方法 var key = primer ? function(x) {return primer(x[field])} : function(x) {return x[field]}; reverse = [-1, 1][+!!reverse]; return function (a, b) { return a = key(a), b = key(b), reverse * ((a > b) - (b > a)); } } test1_sort=test1.sort(sort_by('total', true, parseInt)); //根据total,升序排 console.log(test1_sort); test1_sort=test1.sort(sort_by('name', false, '')); //根据name,倒序排 console.log(test1_sort);