1 回答
TA贡献1836条经验 获得超3个赞
// 做起来很快。可能不是一个有效的解决方案。// 在http://playcode.io 中运行
const data = {
"Isabela Alves de Quadros":{
"2019-10-22":4500,
"2019-10-25":120,
"2019-11-04":60
},
"Naiara":{
"2019-10-25":5000,
"2019-10-28":10,
"2019-10-31":6000
},
"Nathália":{
"2019-10-17":15,
"2019-11-01":125
}
}
console.log(data)
var names = Object.keys(data);
console.log(names);
var dates = Object.values(data);
console.log(dates);
var allDates = dates.map((item) => (Object.keys(item)));
console.log(allDates);
var merged = ([].concat.apply([], allDates));
var dist = new Set(merged);
console.log(dist);
var finalData = [];
for(let name of names)
{
var dates = [];
for (let [key, value] of dist.entries())
{
var tempDates = data[name];
if(tempDates[key] != undefined){
dates.push(tempDates[key]);
}
else{
dates.push(null);
}
}
finalData.push( {name: name, data:dates})
}
console.log(finalData);
添加回答
举报