I have some code which:
- gets all id's from a js array of objects
- creates a distinct list of those id's into a new variable
- 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?