[javascript]object array sort example
//陣列 var array = [ { ID:1, Name:'Chou' }, { ID:5, Name:'Lee' }, { ID:3, Name:'Chen' } ]; //依照ID排序 array.sort(function (a, b) { return a.ID > b.ID ? 1 : -1; }); //依照時間排序 var array2 = [ { ID:1, Date:'2015-01-01T23:59:59' }, { ID:5, Date:'2015-01-04T13:00:00' }, { ID:3, Date:'2015-01-05T14:00:00' } ]; Data.sort(function (a, b) { return new Date(b.Date) - new Date(a.Date); });