将第二个数组中匹配的日期对应的 inOutAmount 添加到新数组中,而不需要日期信息
// 第一个数组
const datesArray = [
"2023-03", "2023-04", "2023-05", "2023-06", "2023-07", "2023-08",
"2023-09", "2023-10", "2023-11", "2023-12", "2024-01", "2024-02"
];
// 第二个数组
const amountsArray = [
{
"keys": "2024-01",
"inOutAmount": 257.9216
},
{
"keys": "2023-11",
"inOutAmount": 10515.355654
},
{
"keys": "2023-12",
"inOutAmount": 411.08244
}
];
// 创建新数组并初始化为 0
const resultArray = Array(datesArray.length).fill(0);
// 匹配日期并添加对应的inOutAmount
amountsArray.forEach(item => {
const index = datesArray.indexOf(item.keys);
if (index !== -1) {
resultArray[index] = item.inOutAmount;
}
});
// 打印结果
console.log(resultArray);
const ContainerType = [
{
value: "0",
label: "袋装",
color: 'green'
},
{
value: "10",
label: "桶装",
color: 'yellow'
},
{
value: "20",
label: "箱装",
color: 'orange'
},
{
value: "30",
label: "瓶装",
color: 'olive'
},
{
value: "40",
label: "罐装",
color: 'pink'
},
{
value: "50",
label: "卡板装",
color: 'blue'
},
{
value: "60",
label: "编织袋",
color: 'purple'
}
];
this.copyData2.map(item => {
const containerTypeItem = ContainerType.find(type => type.value === item.containerCategory);
if (containerTypeItem) {
item.containerCategory = containerTypeItem.label;
}
});