Sort object groups based on condition
This question already has an answer here:
假设你的结果数组叫做数据,它看起来像这样:
data.sort(function(a,b){
if (a.name > b.name) return 1;
return -1;
});
The previous post isn't correct, because 0 is never returned. This will work for your case.
yourData.sort(function(a, b){
if (a.name > b.name) {
return 1
}
if (a.name < b.name) {
return -1
}
else {
return 0
}
});
链接地址: http://www.djcxy.com/p/19342.html
上一篇: 使用JavaScript对数组进行排序
下一篇: 根据条件对对象组进行排序