js合并相同值的数组,生成一组新的数组

得到的数据:
vardata=[
{"year":"2018-03-03","qidong":"17:01:37","shicha":"25","jieshu":"17:02:03"},
{"year":"2018-03-03","qidong":"17:01:06","shicha":"14","jieshu":"17:01:20"},
{"year":"2018-03-04","qidong":"17:00:41","shicha":"11","jieshu":"17:00:52"},
{"year":"2018-03-04","qidong":"17:00:06","shicha":"7","jieshu":"17:00:13"}
];
请教如何把数组生成新的类型数组?如下
vardata=[
{"year":"2018-03-03","qidong":"17:01:37,17:01:06","shicha":"25,14","jieshu":"17:02:03,17:01:20"},
{"year":"2018-03-04","qidong":"17:00:41,17:00:06","shicha":"11,7","jieshu":"17:00:52,17:00:13"},
];
紫衣仙女
浏览 705回答 2
2回答

翻过高山走不出你

vardata=[{"year":"2018-03-03","qidong":"17:01:37","shicha":"25","jieshu":"17:02:03"},{"year":"2018-03-03","qidong":"17:01:06","shicha":"14","jieshu":"17:01:20"},{"year":"2018-03-04","qidong":"17:00:41","shicha":"11","jieshu":"17:00:52"},{"year":"2018-03-04","qidong":"17:00:06","shicha":"7","jieshu":"17:00:13"}];var_=data.reduce(function(a,b){varyear=b.year;if(!a[year]){a[year]={qidong:[],shicha:[],jieshu:[]}}a[year].qidong.push(b.qidong);a[year].shicha.push(b.shicha);a[year].jieshu.push(b.jieshu);returna;},{});_=Object.keys(_).map(function(item){return{year:item,qidong:_[item].qidong.join(','),shicha:_[item].shicha.join(','),jieshu:_[item].jieshu.join(','),};})console.log(_);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript