How to get the 3 latest date from array of objects in client side?

  angular, javascript, typescript

I’m using angular 7 in project.

Here is the Array (in JSON) that I get from server:

[
  {
    "Address": 25,
    "Date": "2019-02-01T00:01:01.001Z",
  },
  {
    "Address": 26,
    "Date": "2016-04-12T15:13:11.733Z",
  },
  {
    "Address": 25,
    "Date": "2020-02-01T00:01:01.001Z",
  },
  {
    "Address": 36,
    "Date": "2021-02-01T00:01:01.001Z",
  }
          .
          .
          .
]

I need to get 3 the latest date from the array.

For get the latest date from array I used this.CrewChannelContentsByDate = this.CrewChannelContents.reduce((a, b) => (a.Date > b.Date ? a : b)); I want to get 3 latest?

Can you share with me any idea please?

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.