How to sum values in typescript array based on array items property?

Arrays in JavaScript/TypeScript also have these kind of methods. You can again filter with you condition and then use reduce aggregation function to sum the items.

const sum = receiptItems.filter(item => item.tax === '25.00')
                        .reduce((sum, current) => sum + current.total, 0);

item.tax === '25.00' – this part you must adjust with your logic

Leave a Comment