@dc65k

Как правильно отсортировать свойства данные по дате и времени?

Всем привет, подскажите, пожалуйста как правильно отсортировать следующие данные по дате и времени?
Чтобы затем с помощью, например объекта Date, получить необходимые данные.
const dates = [
    {date: "14.01.2021T22:09:12", title: 1},
    {date: "14.01.2021T22:08:17", title: 2},
    {date: "14.01.2021T21:58:03", title: 4},
    {date: "14.01.2021T21:54:38", title: 5},
    {date: "14.01.2021T22:04:12", title: 3},
    {date: "14.01.2021T21:51:24", title: 6},
    {date: "14.01.2021T21:48:35", title: 7},
    {date: "14.01.2021T21:33:49", title: 8},
    {date: "14.01.2021T21:07:42", title: 10},
    {date: "14.01.2021T21:05:22", title: 11},
    {date: "14.01.2021T21:09:09", title: 9},
    {date: "14.01.2021T21:03:57", title: 12},
    {date: "14.01.2021T21:02:14", title: 13},
    {date: "14.01.2021T20:21:21", title: 14},
    {date: "14.01.2021T19:59:39", title: 15},
    {date: "14.01.2021T19:47:47", title: 17},
    {date: "14.01.2021T19:40:28", title: 18},
    {date: "14.01.2021T19:49:24", title: 16},
    {date: "14.01.2021T19:29:51", title: 19},
    {date: "14.01.2021T19:28:40", title: 20},
    {date: "14.01.2021T14:08:19", title: 21},
    {date: "14.01.2021T13:59:29", title: 22},
    {date: "14.01.2021T13:56:22", title: 24},
    {date: "14.01.2021T13:56:14", title: 25},
    {date: "14.01.2021T13:55:50", title: 26},
    {date: "14.01.2021T13:55:42", title: 27},
    {date: "14.01.2021T13:55:29", title: 28},
    {date: "15.01.2021T07:07:19", title: 0},
    {date: "14.01.2021T13:56:57", title: 23},
    {date: "14.01.2021T11:33:55", title: 29},
    {date: "14.01.2021T11:14:28", title: 30},
    {date: "13.01.2021T18:59:53", title: 31},
    {date: "13.01.2021T17:18:11", title: 32},
    {date: "13.01.2021T17:11:35", title: 33},
    {date: "13.01.2021T13:46:57", title: 40},
    {date: "13.01.2021T13:35:57", title: 41},
    {date: "13.01.2021T13:05:20", title: 42},
    {date: "13.01.2021T13:02:12", title: 43},
    {date: "13.01.2021T12:56:21", title: 44},
    {date: "13.01.2021T17:00:17", title: 34},
    {date: "13.01.2021T16:59:36", title: 35},
    {date: "13.01.2021T16:56:56", title: 36},
    {date: "13.01.2021T16:49:00", title: 37},
    {date: "13.01.2021T15:06:49", title: 38},
    {date: "13.01.2021T14:03:52", title: 39},
    {date: "13.01.2021T12:55:43", title: 45},
    {date: "13.01.2021T12:30:40", title: 46},
    {date: "13.01.2021T11:50:36", title: 47},
    {date: "12.01.2021T15:06:30", title: 48},
    {date: "12.01.2021T13:36:05", title: 49},
    {date: "12.01.2021T13:13:29", title: 50},
    {date: "12.01.2021T13:11:55", title: 51},
    {date: "12.01.2021T13:03:05", title: 52},
    {date: "12.01.2021T12:58:25", title: 53},
    {date: "12.01.2021T12:56:30", title: 54},
    {date: "12.01.2021T12:43:40", title: 55},
    {date: "12.01.2021T11:03:03", title: 56},
    {date: "12.01.2021T11:01:49", title: 57},
    {date: "12.01.2021T11:01:13", title: 58},
    {date: "12.01.2021T11:00:50", title: 59},
]
  • Вопрос задан
  • 93 просмотра
Решения вопроса 1
0xD34F
@0xD34F Куратор тега JavaScript
const sortedArr = arr
  .map(n => [ n, new Date(n.date.replace(/(\d+)\.(\d+)\.(\d+)/, '$3-$2-$1')) ])
  .sort((a, b) => a[1] - b[1])
  .map(n => n[0]);
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы