如何在下面的代码中使用JS Map Correclty抛出错误?

时间:2019-05-30 18:24:58

标签: javascript arrays ecmascript-6

不确定我是否在代码下面丢失了任何东西是否抛出了错误映射,这不是函数吗?

有什么更好的方法可以使代码达到结果?

main.js

const errorCodes = [99,890];
    const drug = [{
        "isBrand": true,
        "drugName": "Lipitor",
        "specialtyPrice": {}
      },
      {
        "isBrand": false,
        "drugName": "Atorvastatin Calcium",
        "drugStrength": "80mg",
        "drugForm": "Tablet",
        "mailPrice": {
          "totalQuantity": 90,
          "rejectMessage": [{
            "settlementCode": "99",
            "settlementDesc": "Sorry, the system is temporarily:Lo sentimos,Intente(Código de error 85)"
          }]
        },
        "retailPrice": {
          "totalQuantity": 30,
          "rejectMessage": [{
            "settlementCode": "99",
            "settlementDesc": "Sorry, the system is temporarily:Lo sentimos,Intente(Código de error 85)"
          }]
        },
        "specialtyPrice": {}
      }
    ];

          const filteredPrices = drug.map(item => {
            const errorCodes = drugPriceErrors;
            const pricePath = ['mailPrice.rejectMessage', 'retailPrice.rejectMessage'];

            _.forEach(pricePath, function (path)  {
              const rejectMsg = _.get(item, path);
              const hasCode = rejectMsg && rejectMsg.find(i => !!~errorCodes.indexOf(+i.settlementCode));
              hasCode && delete item[path.split('.').shift()];
            });

            return item;
          });

错误:

TypeError: drug.map is not a function

0 个答案:

没有答案