1.日期正序排列(日期从小到大)
function ForwardRankingDate(data, p) { for (i = 0; i < data.length - 1; i++) { for (j = 0; j < data.length - 1 - i; j++) { if (Date.parse(data[j][p]) > Date.parse(data[j+1][p])) { var temp = data[j]; data[j] = data[j + 1]; data[j + 1] = temp; } } } return data; } ForwardRankingDate(value, "time");
2.日期倒序排列
function ReverseRankingDate(data, p) { for (i = 0; i < data.length - 1; i++) { for (j = 0; j < data.length - 1 - i; j++) { if (Date.parse(data[j][p]) < Date.parse(data[j+1][p])) { var temp = data[j]; data[j] = data[j + 1]; data[j + 1] = temp; } } } return data; } ReverseRankingDate(result, "name");
原文地址:https://www.cnblogs.com/menxiaojin/p/12108549.html
时间: 2024-10-19 16:16:18