I have an array with different objects and they have different date fields that i want to sort regardless of the property name created_at
, order_date
or updated_at
. How can i sort the array by the nearest date to today's date ?
The array looks like this :
const array = [{type : 'type1', created_at: '2021-07-31'}, {type : 'type2', order_date: '2021-07-13'}, {type : 'type2', order_date: '2021-07-07'}, {type : 'type1', created_at: '2021-08-05'}, {type : 'type3', updated_at: '2021-09-05'}];