有一个时间数组对象,时次不连续,怎样补全比较好?
需要展示出一天中所有小时的数据,后端返回的数据是这样
beforData: [
{
"time_hours": "09", // 时间
"approved_amount": 28068.0,
"pass_rate": 1.0
},
{
"time_hours":"10",
"approved_amount":0.0,
"pass_rate":0.0
},
{
"time_hours":"11",
"approved_amount":42706.0,
"pass_rate":0.5
},
{
"time_hours":"13",
"approved_amount":0.0,
"pass_rate":0.0
},
{
"time_hours":"15",
"approved_amount":37700.0,
"pass_rate":0.5714285714
},
{
"time_hours":"16",
"approved_amount":0.0,
"pass_rate":0.0
},
{
"time_hours":"17",
"approved_amount":29520.0,
"pass_rate":0.6
},
{
"time_hours":"18",
"approved_amount":0.0,
"pass_rate":0.0
},{
"time_hours":"19",
"approved_amount":56216.0,
"pass_rate":1.0
},
{
"time_hours":"22",
"approved_amount":5800.0,
"pass_rate":1.0
},
{
"time_hours":"23",
"approved_amount":0.0,
"pass_rate":0.0
}
]
需要将缺少的小时补全,转化成
[
{
"time_hours": "01:00",
"approved_amount": null,
"pass_rate": null,
},
{
"time_hours": "02:00",
"approved_amount": null,
"pass_rate": null,
},
{
"time_hours": "03:00",
"approved_amount": null,
"pass_rate": null,
},
{
"time_hours": "04:00",
"approved_amount": null,
"pass_rate": null,
},
{
"time_hours": "05:00",
"approved_amount": null,
"pass_rate": null,
},
{
"time_hours": "06:00",
"approved_amount": null,
"pass_rate": null,
},
{
"time_hours": "07:00",
"approved_amount": null,
"pass_rate": null,
},
{
"time_hours": "08:00",
"approved_amount": null,
"pass_rate": null,
},
{
"time_hours": "09:00",
"approved_amount": 28068.0,
"pass_rate": 1.0
},
{
"time_hours":"10:00",
"approved_amount":0.0,
"pass_rate":0.0
},
{
"time_hours":"11:00",
"approved_amount":42706.0,
"pass_rate":0.5
},
{
"time_hours": "12:00",
"approved_amount": null,
"pass_rate": null,
},
{
"time_hours":"13:00",
"approved_amount":0.0,
"pass_rate":0.0
},
{
"time_hours": "14:00",
"approved_amount": null,
"pass_rate": null,
},
{
"time_hours":"15:00",
"approved_amount":37700.0,
"pass_rate":0.5714285714
},
{
"time_hours":"16:00",
"approved_amount":0.0,
"pass_rate":0.0
},
{
"time_hours":"17:00",
"approved_amount":29520.0,
"pass_rate":0.6
},
{
"time_hours":"18:00",
"approved_amount":0.0,
"pass_rate":0.0
},{
"time_hours":"19:00",
"approved_amount":56216.0,
"pass_rate":1.0
},
{
"time_hours": "20:00",
"approved_amount": null,
"pass_rate": null,
},
{
"time_hours": "21:00",
"approved_amount": null,
"pass_rate": null,
},
{
"time_hours":"22:00",
"approved_amount":5800.0,
"pass_rate":1.0
},
{
"time_hours":"23:00",
"approved_amount":0.0,
"pass_rate":0.0
},
{
"time_hours": "00:00",
"approved_amount": null,
"pass_rate": null,
},
]
这样的,请教一下大家这个要怎么做啊?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不谢,拿走:
就这么简单~~~
补充一个线性时间复杂度的
Array.prototype.map
既然结果是固定的 就反过来遍历呗