var sortByProperty = function (property) {
return function (x, y) {
return ((x[property] === y[property]) ? 0 : ((x[property] > y[property]) ? 1 : -1));
};
};
调用:
someArray.sort(sortByProperty('id'));
方法来自:https://davidsimpson.me/2014/05/22/how-to-sort-an-array-of-json-arrays/
网友评论