0👍
✅
Reduce() is an array function in javascript. You either want to use forEach for your object or rewrite it to an array.
const data = [
{ deduction: 625 },
{ deduction: 500 },
{ deduction: 2500 },
{ grandTotal: 8460 },
{ otTotal: 50 },
];
function totaldeduct(data) {
return data.reduce((acc, item) => {
if(item.deduction)
return acc + item.deduction;
else return acc
}, 0);
}
let reduced = totaldeduct(data);
console.log(reduced);
Source:stackexchange.com