// 有以下数组arr
let arr = [
{
dt: "2021-01",
org_name: "雪肌",
ordercount: 6860,
amountsum: 5279333.89,
},
{
dt: "2021-01",
org_name: "智美",
ordercount: 315,
amountsum: 1632081.63,
},
{
dt: "2021-01",
org_name: "易购",
ordercount: 19267,
amountsum: 576536.02,
},
{
dt: "2021-01",
org_name: "新云商",
ordercount: 7937,
amountsum: 383853.12,
},
{
dt: "2021-02",
org_name: "雪肌",
ordercount: 5923,
amountsum: 5337823.19,
},
{
dt: "2021-02",
org_name: "智美",
ordercount: 143,
amountsum: 1444326.27,
},
{
dt: "2021-02",
org_name: "新云商",
ordercount: 7679,
amountsum: 395459.04,
},
{
dt: "2021-02",
org_name: "易购",
ordercount: 2959,
amountsum: 164336.91,
},
{
dt: "2021-03",
org_name: "智美",
ordercount: 462,
amountsum: 14206588.23,
},
{
dt: "2021-03",
org_name: "雪肌",
ordercount: 5755,
amountsum: 6186629.37,
},
{
dt: "2021-03",
org_name: "易购",
ordercount: 18956,
amountsum: 749612.85,
},
{
dt: "2021-03",
org_name: "新云商",
ordercount: 4835,
amountsum: 225894.92,
},
{ dt: "2021-03", org_name: "雪莉", ordercount: 2, amountsum: 30083 },
{
dt: "2021-04",
org_name: "雪肌",
ordercount: 7576,
amountsum: 4810868.25,
},
{
dt: "2021-04",
org_name: "智美",
ordercount: 402,
amountsum: 2199224.42,
},
{
dt: "2021-04",
org_name: "雪莉",
ordercount: 23,
amountsum: 1240743.64,
},
{
dt: "2021-04",
org_name: "易购",
ordercount: 8137,
amountsum: 509817.85,
},
{
dt: "2021-04",
org_name: "新云商",
ordercount: 3146,
amountsum: 129066.09,
},
{
dt: "2021-05",
org_name: "雪肌",
ordercount: 1979,
amountsum: 1443072.02,
},
{
dt: "2021-05",
org_name: "智美",
ordercount: 98,
amountsum: 1173696.93,
},
{
dt: "2021-05",
org_name: "易购",
ordercount: 5841,
amountsum: 216819.41,
},
{ dt: "2021-05", org_name: "雪莉", ordercount: 3, amountsum: 120986 },
{
dt: "2021-05",
org_name: "新云商",
ordercount: 1705,
amountsum: 62176.13,
},
];
// 要得到以下数组
newArr = [
{
dt: "2021-01",
org_name: "雪莉",
ordercount: 0,
amountsum: 0,
},
{
dt: "2021-01",
org_name: "雪肌",
ordercount: 6860,
amountsum: 5279333.89,
},
{
dt: "2021-01",
org_name: "智美",
ordercount: 315,
amountsum: 1632081.63,
},
{
dt: "2021-01",
org_name: "易购",
ordercount: 19267,
amountsum: 576536.02,
},
{
dt: "2021-01",
org_name: "新云商",
ordercount: 7937,
amountsum: 383853.12,
},
{
dt: "2021-02",
org_name: "雪莉",
ordercount: 0,
amountsum: 0,
},
{
dt: "2021-02",
org_name: "雪肌",
ordercount: 5923,
amountsum: 5337823.19,
},
{
dt: "2021-02",
org_name: "智美",
ordercount: 143,
amountsum: 1444326.27,
},
{
dt: "2021-02",
org_name: "新云商",
ordercount: 7679,
amountsum: 395459.04,
},
{
dt: "2021-02",
org_name: "易购",
ordercount: 2959,
amountsum: 164336.91,
},
{
dt: "2021-03",
org_name: "智美",
ordercount: 462,
amountsum: 14206588.23,
},
{
dt: "2021-03",
org_name: "雪肌",
ordercount: 5755,
amountsum: 6186629.37,
},
{
dt: "2021-03",
org_name: "易购",
ordercount: 18956,
amountsum: 749612.85,
},
{
dt: "2021-03",
org_name: "新云商",
ordercount: 4835,
amountsum: 225894.92,
},
{ dt: "2021-03", org_name: "雪莉", ordercount: 2, amountsum: 30083 },
{
dt: "2021-04",
org_name: "雪肌",
ordercount: 7576,
amountsum: 4810868.25,
},
{
dt: "2021-04",
org_name: "智美",
ordercount: 402,
amountsum: 2199224.42,
},
{
dt: "2021-04",
org_name: "雪莉",
ordercount: 23,
amountsum: 1240743.64,
},
{
dt: "2021-04",
org_name: "易购",
ordercount: 8137,
amountsum: 509817.85,
},
{
dt: "2021-04",
org_name: "新云商",
ordercount: 3146,
amountsum: 129066.09,
},
{
dt: "2021-05",
org_name: "雪肌",
ordercount: 1979,
amountsum: 1443072.02,
},
{
dt: "2021-05",
org_name: "智美",
ordercount: 98,
amountsum: 1173696.93,
},
{
dt: "2021-05",
org_name: "易购",
ordercount: 5841,
amountsum: 216819.41,
},
{ dt: "2021-05", org_name: "雪莉", ordercount: 3, amountsum: 120986 },
{
dt: "2021-05",
org_name: "新云商",
ordercount: 1705,
amountsum: 62176.13,
},
];
虽然这么多人吐槽,但是我还是想吃分啊。果然还是吃分快乐。(mac 的快捷键功能能不能给加一下,它没有 ctrl )
我们先来分析,把题主提供的数据粘贴到控制台中。然后输出一下,哎呦,新数组多数据了(圈住,要考)
接下来,我们点开看看能不能找到规律
规律还可以。就是把每天没出售的商品补全,那我们先来搞一下都有哪些商品
Array.from(new Set(arr.map(v=>v.org_name)))
,同理得出有多少天接下来就是遍历填充数据了。
好了问题已经解决了。还是建议你下次提问要把问题描述的更清晰一点。
答题也就只能得一点分而已,又不是得到钱了。(社区大佬们都是日薪过千,时薪过百,那算下来一分钟好几块钱呢,你说说答一道描述不清的题浪费多少时间和金钱)