TypeScript sort by date not working

后端 未结 4 1857
后悔当初
后悔当初 2020-12-18 17:43

I have an object TaskItemVO with field dueDate which has the type Date:

export class TaskItemVO {
    
    public dueDa         


        
4条回答
  •  抹茶落季
    2020-12-18 18:13

    As possible workaround you can use unary + operator here:

    public sortByDueDate(): void {
        this.myArray.sort((a: TaskItemVO, b: TaskItemVO) => {
            return +new Date(a.dueDate) - +new Date(b.dueDate);
        });
    }
    

提交回复
热议问题