find的使用

将第二个数组中匹配的日期对应的 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;
  }
});

  • 10
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值