I have this data array retrieved from the database with Axios, I want to return the sum of a field based on some conditions
I already used map() to grab the data from my backend :
// getData.js
return (
<ul>
{attendance.map(({ _id, name, male }) => {
return (
<div key={_id}>
<br />
<hr />
<li>{name}</li>
{/* the condition is to render only male that are >= 2 */}
<li>{male >= 2 ? male : 0}</li>
</div>
)
})}
</ul>
)
//output
Joshua Jaccob
2
Fabio Rio
2
Lancelot Abe
2
Bello
0
Becca Andrew
0
I want to sum the total male that fit the condition, also render only those that fit the condition