I am working on a chat application and I have an array of messages which each have a timestamp property. I need to get all the days in the array where at least 1 message is sent, like in WhatsApp. The idea is to display a separator between the messages on different days, with the separator being just before the first message of the day specified.
For example if the array of messages was
[
{
message: "Hey",
timestamp: (1st January 2020)
},
{
message: "Hi",
timestamp: (1st January 2020)
},
{
message: "Hello",
timestamp: (3rd January 2020)
},
]
Then the expected output would be
[(1st January 2020), (3rd January 2020)]
or even better
[
{
type: "Seperator",
day: (1st January 2020)
},
{
message: "Hey",
timestamp: (1st January 2020)
},
{
message: "Hi",
timestamp: (1st January 2020)
},
{
type: "Seperator",
day: (3rd January 2020)
},
{
message: "Hello",
timestamp: (3rd January 2020)
}
]