2.想要得到的结果
3、实现过程,主要是两个数组长度相同,用哪一个做循环都可以
这就是整一个实现过程
var da={"success": {"1": [{"t":"A4","c":"2017/7/3"}, {"t":"A2","c":"2017/7/3"}, {"t":"A3","c":"2017/7/4"}, {"t":"A1","c":"2017/7/4"}], "2": [{"t":"B4","c":"2017/7/3"}, {"t":"B2","c":"2017/7/3"}, {"t":"B3","c":"2017/7/4"}, {"t":"B1","c":"2017/7/4"}], "3": [{"t":"C4","c":"2017/7/3"}, {"t":"C2","c":"2017/7/3"}, {"t":"C3","c":"2017/7/4"}, {"t":"C1","c":"2017/7/4"}] } }var timesmap = {}
for(var box0 in da.success)
for(var box1 of da.success[box0]) {
if(!timesmap[box1.c])
timesmap[box1.c] = []
timesmap[box1.c].push(box1.t)
}
var ret = []
for(var time in timesmap) {
var item = [time]
for(var box0 of timesmap[time])
item.push(box0)
ret.push(item)
}
console.log(ret)
写好了,你看看。