Skip to content

Instantly share code, notes, and snippets.

@luokailuo
Last active May 17, 2016 07:30
Show Gist options
  • Save luokailuo/8c3c7b72f314b8210ef4a9a1878f55a5 to your computer and use it in GitHub Desktop.
Save luokailuo/8c3c7b72f314b8210ef4a9a1878f55a5 to your computer and use it in GitHub Desktop.
利用sort()方法对Array进行日期时间排序
var data = get_data();
//降序
data.sort( function(a, b){
return a["createAt" ] < b["createAt" ] ? 1 : a["createAt" ] == b["createAt" ] ? 0 : -1;
});
//升序
data.sort( function(a, b){
return a["createAt" ] > b["createAt" ] ? 1 : a["createAt" ] == b["createAt" ] ? 0 : -1;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment