How can I make this code return values instead of arrays? This is my representation, where the idea is to check whether IDs match between each other and get a priceList array of matching values. Can this be simplified, or perhaps replaced with .reduce()? Need extra help with this
const priceList = options.map((productOption) => {
const { data } = productOption;
return data.filter(({ option_type_id, price }) => {
if (selectedOptionsArray.indexOf(option_type_id) !== -1) {
return price;
}
return 0;
});
});
Array.prototype.mapalways returns an array..map->.flatMap. But if it's something different, I'm not sure..filter()has to return a boolean. Why do you return an arbitrary number instead?mapinstead offilteryou will get an array of numbers.