Skip to content
Advertisement

How to Map objects inside an array – Javascript

This is for a React Native Chat app.

My data should be something like this:

JavaScript

I am listing the Chat list using a FlatList:

JavaScript

The messages shows like this all stacked up and I am not what is the workaround. What I am trying to achieve is displaying the last message based on timestamp.

enter image description here

Advertisement

Answer

To get the last message of the messages array, set the message attribute of the MessageItem element to the last message, like so:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement