-1

ARRAY.sort(function(a,b){return a-b});

this code sorts an array from highest to lowest. I have a property that i want it to use to sort the array, since each element has 3 properties, and one of them is "time" which is what i want it to check and sort based on.

But i can't do Array.time.sort. How would i accomplish this?

Vincent
  • 37
  • 8
  • https://stackoverflow.com/questions/1129216/sort-array-of-objects-by-string-property-value try that? – Canvas Sep 14 '20 at 21:50

1 Answers1

0

Figured it out, this works:

ARRAY.sort(function(b,a){return a.time- b.time}); "time" being the property you want to access, for me it's time. To get lowest to highest, replace the locations of (b, a)

Vincent
  • 37
  • 8