const values = dataSku.map(sku => {return map.skuInfo[sku].description})
Here, there is some posibility that map.skuInfo[sku] can be null/undefined and I need to filter it. How would it be possible ?
Sounds like you want .filter
. It's a higher order function like .map
.
const values = dataSku
.filter(item => item.description !== undefined)
I'm not sure your exact data structure but check it out here! It filters out all non-truthy return values.
This will solve your problem -
const values = dataSku.map(sku => map.skuInfo[sku]}).filter(skuInfo => typeof skuInfo !== "undefined").map(skuInfo => skuInfo.description);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With