0
constructor(props) {
super(props);
 let comments = [{body: "good", created_at:"2018-02-12T05:27:47.175Z"},
                 {body: "bad article", created_at:"2017-11-12T05:27:47.175Z"}, 
                 {body: "great", created_at:"2017-10-12T05:27:47.175Z"}];
  this.state = { comments };
render() {
 return(
 { comments.map((comment, index) =>
    <Text>{comment.body}</Text>
  )}
 );
};

The data comes in descending order but, I want to sort it in ascending order based on created_at date.

Now, comment which is new is coming first and I want comment which is old should come first.

How can I sort this comments? Please suggest any solution.

kalyani_jamunkar
  • 582
  • 1
  • 13
  • 33

1 Answers1

9

Add a .reverse().

comments.reverse().map((comment) =>
  <Text>{comment.body}</Text>
);
dork
  • 4,396
  • 2
  • 28
  • 56