当我有这样的数组时
var test = [['11 may 2018',0],['11 may 2018',1],['12 may 2018',5],['13 may 2018',0],['14 may 2018',0],['15 may 2018',3],['15 may 2018',7],['16 may 2018',30]];
我希望它最终看起来像这样
var test2 = [['11 may 2018',1],['12 may 2018',5],['13 may 2018',0],['14 may 2018',0],['15 may 2018',10],['16 may 2018',30]]
我不知道该怎么做。
我做了类似的事情:
var test = [['11 may 2018',0],['11 may 2018',1],['12 may 2018',5],['13 may 2018',0],['14 may 2018',0],['15 may 2018',3],['15 may 2018',7],['16 may 2018',30]];
var test2 = [['11 may 2018',1],['12 may 2018',5],['13 may 2018',0],['14 may 2018',0],['15 may 2018',10],['16 may 2018',30]]
var testLength = test.length;
for (let i = 0; i< testLength; i++){
if(i != testLength -1){
if(test[i][0] == test[i+1][0]){
test[i][1] += test[i+1][1];
}
}
}
console.log(test)
哪个返回
[
[ '11 may 2018', 1 ],
[ '11 may 2018', 1 ],
[ '12 may 2018', 5 ],
[ '13 may 2018', 0 ],
[ '14 may 2018', 0 ],
[ '15 may 2018', 10 ],
[ '15 may 2018', 7 ],
[ '16 may 2018', 30 ]
]
我不知道如何在不弄乱索引的情况下删除重复数组的第二个实例
扬帆大鱼
PIPIONE
潇潇雨雨
相关分类