https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
参考上述链接,打算给数组的Time元素进行排序,但是发现console.log打印出来的不对。
列表如下
MeetingAgenda: [
{ Content: “Test 5”, Time: “08:30 - 09:30”, Comment: “VincentDeng-15914137911”, Index: 8},
{ Content: “Test 2”, Time: “09:30 - 10:30”, Comment: “VincentDeng-15914137911”,Index: 2},
{ Content: “Test 3”, Time: “07:30 - 08:30”, Comment: “VincentDeng-15914137911”, Index: 3 },
]
代码如下:
console.log(“sort result”);
console.log(this.data.MeetingAgenda.sort(function(a, b){
if(a.Time - b.Time > 0)
{
return -1;
}
else
{
return 1;
}
}));
结果如下:
没找到原因?是写法不对吗?