Previously, I successfully combined two arrays into one and sorted them by the created_at
property using the sort()
method.
let result = [...item.messages, ...item.chat_messages]
result.sort((a, b) => new Date(b.created_at) - new Date(a.created_at))
item.messages = result
Now, I am faced with a new challenge. I need to incorporate another array (sms_messages) into this existing array and sort it based on its scheduled_at
field.
Is there a way to achieve this using the same approach as before?
let result = [...item.messages, ...item.chat_messages, ...item.sms_messages]
// then order by messages' and chat_messages' created_at (as done previously) along with
// sms_messages' scheduled_at