Viktor Molnar
Viktor Molnar

Reputation: 99

Sorting Data in Array with Angular7/firebase

I need help with sorting data in array, I want to sort Time in my table. My time format have HH:MM, in firebase its: {hour:07,minute:15}, and this is how i sort with hour:

this.array.sort((a, b) => a.data.hour- b.data.hour);

Evryting is ok till i face two same hours: enter image description here

Is there chance to sort hours first than minutes? Or any other idea is acceptable.

Upvotes: 1

Views: 51

Answers (1)

Hassan Imam
Hassan Imam

Reputation: 22574

You can first sort on hour and then on minute.

this.array.sort((a, b) => a.data.hour - b.data.hour || a.data.minute - b.data.minute);

Upvotes: 2

Related Questions