我如何按降序对地图数据进行排序,这些数据已在react-native中按升序排序?

kal*_*kar 0 sorting mapping reactjs react-native

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>
  )}
 );
};
Run Code Online (Sandbox Code Playgroud)

数据按降序排列,但我想根据created_at日期按升序排序.

现在,新的评论首先出现,并且想要先老的评语.

我该如何对此评论进行排序?请建议任何解决方案.

dor*_*ork 6

添加.reverse()map.

comments.map((comment, index) =>
  <Text>{comment.body}</Text>
).reverse();
Run Code Online (Sandbox Code Playgroud)