对数组对象根据时间倒序排列
2017-01-12 15:09
375 查看
在接口中查询出来的数据是这样的:
从数据中可以看出,查出来的数据是由时间的升序排序的,有什么方法让这个数组中的对象按时间倒序排列?我想要的结果是这样的:
使用reverse() 颠倒数组中元素的顺序,这时,arr中的对象已经颠倒过来了,比排序还要简单
"contents": [ { "itemContent": "问题提出", "createdOn": 2017-01-6, "itemType": 0, "imgs": [] }, { "itemContent": "回答", "createdOn": 2017-01-12, "itemType": 2, "imgs": [] }, { "itemContent": "小毕", "createdOn": 2017-01-12, "itemType": 2, "imgs": [] }, { "itemContent": "456456465", "createdOn": 2017-01-13, "itemType": 2, "imgs": [] }, { "itemContent": "礼拜四", "createdOn": 2017-01-13, "itemType": 2, "imgs": [] } ]
从数据中可以看出,查出来的数据是由时间的升序排序的,有什么方法让这个数组中的对象按时间倒序排列?我想要的结果是这样的:
"contents": [ { "itemContent": "礼拜四", "createdOn": 2017-01-13, "itemType": 2, "imgs": [] }, { "itemContent": "456456465", "createdOn": 2017-01-13, "itemType": 2, "imgs": [] }, { "itemContent": "小毕", "createdOn": 2017-01-12, "itemType": 2, "imgs": [] }, { "itemContent": "回答", "createdOn": 2017-01-12, "itemType": 2, "imgs": [] }, { "itemContent": "问题提出", "createdOn": 2017-01-6, "itemType": 0, "imgs": [] } ]
使用reverse() 颠倒数组中元素的顺序,这时,arr中的对象已经颠倒过来了,比排序还要简单
var arr = contents.reverse();
相关文章推荐
- js控制input框只能输入数字和一位小数点和小数点后面两位小数
- 自定义 日历 控件
- [Leetcode]113. Path Sum II 求路径和一个数的所有路径
- 并查集
- npm
- Java 泛型
- PHP 行为测试工具 Codeception 介绍
- 自动提示在线/离线状态
- css样式读书笔记
- 深入理解自定义属性
- 机器翻译
- USACO 1.5 数字金字塔 Number Triangles
- KCF 跟踪算法(2)
- iframe跨域
- [Leetcode]404. Sum of Left Leaves
- 分享信息
- Android studio2.2 NDK,JNI的简单使用
- Oracle order by子句对NULL的排序
- mysql InnoDB表插入操作报duplicate entry for primary 却查询不到重复的主键
- 明明的随机数—洛谷 1059