//數組排序例子 var arr = [{name: "zlw", age: 24}, {name: "wlz", age: 25}]; //降序 var compare = function (obj1, obj2) { var val1 = obj1.name; var val2 = obj2.name; if (val1 < val2) { return -1; } else if (val1 > val2) { return 1; } else { return 0; } } arr.sort(compare); console.log(arr);