求js多维数组如何自动累加信息

JavaScript016

求js多维数组如何自动累加信息,第1张

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)

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)

写好了,你看看。