Here's what my array looks like
[
{ name: "myname", date: dateObj, value: 2 },
{ name: "othername", date: dateObj, value: 3 },
{ name: "newname", date: dateObj, value: 5 },
]
Dates are native date objects.
What would be the smartest way to get the one object with the oldest date? Is there a better way than sorting the whole array by looping through?
Is there a better way than sorting the whole array by looping through?. Without iterating through the array, how would you know what's inside it to begin with? It might be that this is the result of some DB query, in which case the best way would be to have the DB sort the returned items.