JS按数组中的“x”排序对象
这个问题在这里已经有了答案:
你可以使用Array.sort() 
array.sort(function(a, b) {
    return a.album < b.album;
});
var array =  [
{'key' :  '1', 'title' :  'title', 'source' :  'path/to/image', 'album' :  'album1'},
{'key' :  '1', 'title' :  'title', 'source' :  'path/to/image', 'album' :  'album2'},
{'key' :  '1', 'title' :  'title', 'source' :  'path/to/image', 'album' :  'album3'},
{'key' :  '1', 'title' :  'title', 'source' :  'path/to/image', 'album' :  'album6'},
{'key' :  '1', 'title' :  'title', 'source' :  'path/to/image', 'album' :  'album5'},
{'key' :  '1', 'title' :  'title', 'source' :  'path/to/image', 'album' :  'album7'},
{'key' :  '1', 'title' :  'title', 'source' :  'path/to/image', 'album' :  'album6'}
];
array.sort(function(a,b){ return a.album > b.album;} );
console.log(array);
http://jsbin.com/xefujehe/1/
查看Array.prototype.sort的MDN文档。
该方法采用比较功能。 这是一个例子:
function compare(a, b) {
  if (a is less than b by some ordering criterion)
     return -1;
  if (a is greater than b by the ordering criterion)
     return 1;
  // a must be equal to b
  return 0;
}
以下是您如何分类专辑名称的方法:
var albums = [
{
    key: 110000,
    album: 'Starry nights'
}, {
    key: 100,
    album: 'Zebra kills Zebra'
}, {
    key: 1,
    album: 'Alfred Hitcock Presents'
}, {
    key: 50,
    album: 'baby whales'
}];
albums.sort(function(a, b){
    return a.album === b.album ? 0 : a.album > b.album;
});
console.log(albums);
的jsfiddle。
排序时请注意,所有大写字母都在全部小写字母之前出现
链接地址: http://www.djcxy.com/p/19333.html