function sortdatalist(propertyName) { var datalist = (object1, object2) => { var value1 = object1[propertyName] var value2 = object2[propertyName] if (value1 < value2) { return -1 } else if (value1 > value2) { return 1 } else { return 0 } } return datalist } //2-----需要重新排序的数组对象 arrdata var arrdata = [ {id:4,name:'张三'}, {id:3,name:'李四'}, {id:2,name:'王二'}, {id:1,name:'麻子'} ] console.log(arrdata.sort(sortdatalist('id')))