i'm facing a problem with filter and reduce. I need to get the sum of "smc" only when "A" is equal 2020. This is my array:
arr = [{A:2020, smc:1},{A:2020, smc:2}, {A:2021, smc:3}]
I've tried something like:
arr.filter(e=> e.A===2020).reduce((sum, iter) => sum + iter.smc)
but it doesn't seem to work. Any ideas why? Thank you