How to use array reduce with condition in JavaScript?
When you return nothing from the reduce function it returns undefined and undefined + 1 === NaN. You should instead filter the array before reducing. records.filter(({gender}) => gender === ‘BOYS’) .reduce((sum, record) => sum + record.value)