I need some help because I'm stuck. If somebody can put me in right direction. the testArr is a much bigger file. But the simple explenation is that I need find the same period and have matching application and based on that have a total count on all payslipCount.
so if I'm searching för a period like '202103' in a date picker. I need to see total paySlipCount for that period and that application. like
period: 202103
pay: Pay100
amount: total amount
testArr = [
{application: "PAY100",
payslipCount: 22,
period: "202101",
},
{application: "PAY100",
payslipCount: 12,
period: "202101",
},
{application: "PAY600",
payslipCount: 0,
period: "202101",
},
{application: "PAY600",
payslipCount: 44,
period: "202101",
},
{application: "PAY600",
payslipCount: 23,
period: "202103",
},
{application: "PAY600",
payslipCount: 44,
period: "202103",
},];
I just need somebody to push I in right direction.
CodePudding user response:
Something like this should do the work. You can replace the date with a variable from the form.
testArr.filter(o => o.period == '202101')
.map(item => item.payslipCount)
.reduce((prev, next) => prev next)