Last active
May 17, 2016 07:30
-
-
Save luokailuo/8c3c7b72f314b8210ef4a9a1878f55a5 to your computer and use it in GitHub Desktop.
利用sort()方法对Array进行日期时间排序
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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