if I have a list of object:
var objectList= LIST_OF_OBJECT;
each object in the list contains three attributes: "name", "date","gender"
How to sort the objects in the list by "date" attribute ascending order?
(the "date" attribute contain string value like "2002-08-29 21:15:31+0500")
If your objects have the date information within a String field:
or, if they have it within a Date field:
The
Array.sort
method accepts a sort function, which accepts two elements as arguments, and should return:.
You're lucky that, in the date format you've provided, a date that is before another date is also
<
than the date when using string comparisons. If this wasn't the case, you'd have to convert the string to a date first:You can try: