Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140762

why is this forEach() var not resolving?

$
0
0

I have some code which:

  1. gets all id's from a js array of objects
  2. creates a distinct list of those id's into a new variable
  3. does a forEach() against the distinct list of ids for 1-by-1 processing
    let commodityIds = supplierPricingInfo.map(x => x.CommodityId);
    let distinctCommodityIds = [...new Set(commodityIds)];
    distinctCommodityIds.forEach(x => {
    sapCommodityRows = supplierPricingInfo.filter(x => x.CommodityId === x);
    debugger;
    });

When my code hits the debugger breakpoint above, a forEach x value of 2 shows in the watch but no matching rows are returned from supplierPricingInfo (although there should be). However, if I hardcode the x variable value to 2 then matching rows are returned from supplierPricingInfo. This is pretty weird. I don't think I've seen an issue like this before. Any idea what the root cause might be?


Viewing all articles
Browse latest Browse all 140762

Latest Images

Trending Articles



Latest Images