I want to use reduce method in an array of objects, but don't seem to find a way out. The code is below. I don't know how can I access the totalDonation property in the object.
const box=document.querySelector(".wholeBox");
let contribution=[
{name:"charles",
totalDonation:1000},
{name:"oliver",
totalDonation:500},
{name:"leo",
totalDonation:300},
];
const totalContribution=contribution.reduce((value,totalValue)=>value + totalValue);
box.innerHTML=totalContribution;
.wholeBox{
height:300px;
width:500px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="wholeBox"></div>
<script src="reduce.js"></script>
</body>
</html>
box.innerHTML=contribution.reduce((total, {totalDonation}) => totalDonation + total, 0);and share feedback, if any.