原json:[{"user":"A","time":"2019.07.23","exactTime":"08:37,12:00,13:34,17:02"},{"user":"A","time":"2019.07.24","exactTime":"08:40,12:00,13:33,17:03"},{"user":"A","time":"2019.07.25","exactTime":"08:25,13:28,17:11"},{"user":"A","time":"2019.07.26","exactTime":"08:20,17:14"},{"user":"B","time":"2019.07.23","exactTime":"08:37,12:04,13:37"},{"user":"B","time":"2019.07.24","exactTime":"12:03,13:28,17:04"},{"user":"B","time":"2019.07.25","exactTime":"08:50,11:50,14:00"}]想得到这样的json格式(根据时间的格式,一般08:xx放到Time1,12:xx放到Time2,13:xx放到Time3,17:xx放到Time4):[{"user":"A","time":"2019.07.23","Time1":"08:37","Time2":"12:00","Time3":"13:34","Time4":"17:02"},{"user":"A","time":"2019.07.24","Time1":"08:40","Time2":"12:00","Time3":"13:33","Time4":"17:03"},{"user":"A","time":"2019.07.25","Time1":"08:25","Time2":"","Time3":"13:28","Time4":"17:11"},{"user":"A","time":"2019.07.26","Time1":"08:20","Time2":"","Time3":"","Time4":"17:14"},{"user":"B","time":"2019.07.23","Time1":"08:37","Time2":"12:00","Time3":"13:34","Time4":"17:02"},{"user":"B","time":"2019.07.24","Time1":"","Time2":"12:02","Time3":"13:28","Time4":"17:04"},{"user":"B","time":"2019.07.25","Time1":"08:50","Time2":"11:50","Time3":"14:00","Time4":""}]
2 回答
ABOUTYOU
TA贡献1812条经验 获得超5个赞
修改原数组版arr.forEach(item=>{letts=item.exactTime.split(',')ts.forEach((tm,index)=>{item['Time'+(index+1)]=tm})})
MMTTMM
TA贡献1869条经验 获得超4个赞
lettimeArr=[{"user":"A","time":"2019.07.23","exactTime":"08:37,12:00,13:34,17:02"},{"user":"A","time":"2019.07.24","exactTime":"08:40,12:00,13:33,17:03"},{"user":"A","time":"2019.07.25","exactTime":"08:25,13:28,17:11"},{"user":"A","time":"2019.07.26","exactTime":"08:20,17:14"},{"user":"B","time":"2019.07.23","exactTime":"08:37,12:04,13:37"},{"user":"B","time":"2019.07.24","exactTime":"12:03,13:28,17:04"},{"user":"B","time":"2019.07.25","exactTime":"08:50,11:50,14:00"}]timeArr.forEach(item=>{letnewTiem=item.exactTime.split(',');for(leti=0;i<4;i++){item['time'+(i+1)]=newTiem[i]||''}})
添加回答
举报
0/150
提交
取消